View RSS Feed

Spring Framework

Beans life in Spring Framework

Rate this Entry
by , 07-07-2012 at 06:37 PM (1379 Views)
The bean has a very simple lifecycle in a normal traditional java application. The bean is instantiated with the new keywork in Java and it is ready to use. When a created bean is not referred by any other object or is not in use, it is collected by the garbage collector.

Bean life cycle in the Spring framework perform extra functionalities. So it is an important part of the Spring framework to understand its bean life cycle so that all the benefits offered by the spring for bean life cycle take effect properly.

Bean Factory

Following steps are performed by the bean factory before bean is able to use:

Instantiate: First the bean is instantiated by the Spring.
Populate properties: The beans properties are injected by the Spring.
Set Bean Name: the bean name is set by the Spring.
Set Bean Factory: The bean factory is passed to setBeanFactory() method to set the bean factory.
Pre Initialization: Also refered as post process method of bean. The postProcessBeforeInitialization() method is called for any BeanPostProcessors.
Initialize bean: The bean is initialized by the Spring framework.
Post Initialization: The spring used postProcessAfterinitialization method for BeanPostProcessors.

Submit "Beans life in Spring Framework" to Facebook Submit "Beans life in Spring Framework" to Digg Submit "Beans life in Spring Framework" to Submit "Beans life in Spring Framework" to StumbleUpon Submit "Beans life in Spring Framework" to Google