ContactUs

Please send your Questions & Answers or Feedback to "mohan@javabook.org"

CORE : What is Bean Life Cycle ?

Problem with the static block :
If there are set of statements to be executed only once like SessionFactory creation and it cannot be implemented in the static block because static block will be executed before injecting the values.

The Solution is BeanLifeCycle : 
1.Implement the InitializingBean and override the afterPropertiesSet(). It is executed only once after injecting the values.It is similar to init() in servlets.
2.Implement DisposableBean and override the destroy(). It is executed only once at the Container destroy time.Its similar to destroy() in servlets.
Note : In servlets the life cycle methods are there in one interface and the lifecycle process is must.In spring, the lifecycle methods are there in different inteerfaces and the lifecycle process is optional.
Related Posts Plugin for WordPress, Blogger...
Flag Counter