Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring Annotation Limitations Vs Spring XML (spring 2.5.6)

 
Ganesh Gowtham
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Ranchers !!!

I am working on migration of Spring XML to Spring Annotaions , Since we have limitation we have to use featured upto spring 2.5.6

As per my idea , we cant achieve all things that we do via XML

Few Limitations with Annotations
-------------------------------------

1) cant declare bean (pojo) as abstract , as we do in XML
2) Factory way of instantiating beans
3) Lazy loading
4) Declaring bean as prototype (or) non prototype
5) Injecting collections to bean

Let me know if we have any work around of above mentioned issues .

Could somebody point out link , where i can see spring annotations limitations .

Thanks in advance
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ganesh Gowtham wrote:HI Ranchers !!!

I am working on migration of Spring XML to Spring Annotaions , Since we have limitation we have to use featured upto spring 2.5.6

As per my idea , we cant achieve all things that we do via XML

Few Limitations with Annotations
-------------------------------------

1) cant declare bean (pojo) as abstract , as we do in XML
2) Factory way of instantiating beans
3) Lazy loading
4) Declaring bean as prototype (or) non prototype
5) Injecting collections to bean

Let me know if we have any work around of above mentioned issues .

Could somebody point out link , where i can see spring annotations limitations .

Thanks in advance


4) @Scope("prototype") on any class changes the scope
5) @Autowired on a setter, constructor, or instance variable that is a Collection will automatically create a Collection for you of the types.


Also, you can always use a combination of xml and annotations. It is never a one way over the other. In many cases, you have to use xml when you don't have the code to add an annotation, like in a DataSource, or TransactionManager.

3) I still never see a good reason to lazy load your beans that are Singletons. For Heap Space management and finding configuration problems early, eager loading is a better solution.

1) Can't you put @Component on an abstract class, such that all subclasses are now beans?

2) Not sure what you looking for here. I can create the pojo Factory as a bean, then inject it in places that can call the factory method when it needs those objects.

Hope that helps

Mark
 
Ganesh Gowtham
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi Mark ,

Thanks for your kind reply .

We construct abstract bean like

How this can be changed using annotation ? can it be done if so how ?


@Scope - i will check this annotation .

Can you eleborate on this please "I can create the pojo Factory as a bean, then inject it in places that can call the factory method when it needs those objects. "



Thanks in advance .
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That last example looks like a Legacy Singleton, not a Factory class. If it is a Singleton and Spring automatically instantiates just one instance, you can refactor that class to be just a class, get rid of the bad old Legacy Singleton pattern. If you can. If not then keep that bean in xml. Remember you aren't required to do everything in annotations or everything in xml, it can be a combination.

Do not use the HibernateTemplate. Unless you are using Hibernate 3.0 or less. If you are using 3.1 or higher, HibernateTemplate is a waste, you get no benefit.


See no problem there. ;)

Mark
 
Ganesh Gowtham
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With @Autowired it perfectly works with abstract classes ,Thanks for info

is there way to create the virtual abstract bean



in above XML case ,we really dont have real abstract class in java ,instead we call hibernamteTemplate (aka sampleDao )

Thanks in advance .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic