• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Scope and Bean life cycle question

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?

 
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic