Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scope and Bean life cycle question

 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys...i am learning spring...and in order to learn spring life cycle i wrote a simple
1) a simple POJO class with an integer member variable and its getter and setter, a pair of default init and destroy method....and two more methods for specific initi and destroy
i have put sysouts in all the getter and setters as well as all the pairs of init and destroy methods.
2) in spring bean definition xml : -

i had two tags of dat bean : -



Now when i test by getting only beanA....i also see sysouts for beanB....allthough i am not getting beanB.....
this gets resolved....when i say scope of beanB as "prototype"..... why does the behavior change then ?

 
Volodymyr Lysenko
Ranch Hand
Posts: 511
1
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you specify init-method or destroy-method on <bean> tag they override default-init-method or default-destroy-method on <beans> tag.

Java class supplied in <bean> tag is bean definition (recipe) for creating actual instances. All instances behave identically as you configure them via annotations or in XML. Singleton scoped bean is created eagerly (when application is deployed or when spring container(ApplicationContext) is created ).
Prototype scoped bean is created every time it is requested.
You have two beans with the same bean definition(java class). The same initialization or detroy method is called for both beans.

Maybe tutorials at this site and this site will be helpful. Then you may cover this a little more difficult tutorial.
Finally you MUST pass this whole chapter.
 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Volodymyr Levytskyi wrote:If you specify init-method or destroy-method on <bean> tag they override default-init-method or default-destroy-method on <beans> tag.

Java class supplied in <bean> tag is bean definition (recipe) for creating actual instances. All instances behave identically as you configure them via annotations or in XML. Singleton scoped bean is created eagerly (when application is deployed or when spring container(ApplicationContext) is created ).
Prototype scoped bean is created every time it is requested.
You have two beans with the same bean definition(java class). The same initialization or detroy method is called for both beans.

Maybe tutorials at this site and this site will be helpful. Then you may cover this a little more difficult tutorial.
Finally you MUST pass this whole chapter.


Thanks a lot Volodymyr.....that helps a lot to understand the behavior ! ...i will go through these links now...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic