aspose file tools*
The moose likes Spring and the fly likes Spring Annotation Limitations Vs Spring XML (spring 2.5.6) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring Annotation Limitations Vs Spring XML (spring 2.5.6)" Watch "Spring Annotation Limitations Vs Spring XML (spring 2.5.6)" New topic
Author

Spring Annotation Limitations Vs Spring XML (spring 2.5.6)

Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

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

Thanks, Ganesh Gowtham
http://ganesh.gowtham.googlepages.com
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Ganesh Gowtham
Ranch Hand

Joined: Mar 30, 2005
Posts: 225



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

Joined: Feb 05, 2001
Posts: 17260
    
    6

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

Joined: Mar 30, 2005
Posts: 225

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 .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring Annotation Limitations Vs Spring XML (spring 2.5.6)