This week's book giveaway is in the Agile forum.
We're giving away four copies of Fixing your Scrum and have Ryan Ripley & Todd Miller on-line!
See this thread for details.
Win a copy of Fixing your Scrum this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Spring Annotation Limitations Vs Spring XML (spring 2.5.6)

 
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic