wood burning stoves 2.0*
The moose likes Spring and the fly likes Scope and Bean life cycle question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Scope and Bean life cycle question" Watch "Scope and Bean life cycle question" New topic
Author

Scope and Bean life cycle question

omkar patkar
Ranch Hand

Joined: Aug 25, 2005
Posts: 231
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 ?


Thanks and Regards
Omkar Patkar (SCJP 1.4)[url]http://javacollectionsnotes.blogspot.com[/url] | [url]http://omkar-myscjpexp.blogspot.com[/url]
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

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.


True person is moral, false is right!
omkar patkar
Ranch Hand

Joined: Aug 25, 2005
Posts: 231
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Scope and Bean life cycle question
 
Similar Threads
java.lang.NoClassDefFoundError: java/util/concurrent/ConcurrentSkipListMap
[Spring Security] No bean named 'springSecurityFilterChain' is defined
problens in spring CustomDataEditor!
XML: multiple bean references - how to change them in one line?
spring 2 & struts 2 doubt