Featured Post

Spring Bean Life Cycle

As you Know now a days Sprig community is growing in rapid manner . This is really developing the emerging technology with a super sonic fast . Today we will discuss about spring bean life cycle what exactly happening in the spring container which is also called as Spring IOC container .

Once the Bean container finds the bean definition in the configuration file the corresponding bean will be loaded based on the Java Reflection API which will instantiating the Object for that bean . Any How as we know the spring is developed based on Core java . If you understand the java 1.5 thoroughly , undertsnding the spring technology is very easy . Any how we are deviating from the real topic . I dont want to feel you bore . So once the Bean object is loaded this bean will follow certain life cycle. If the properties are mentioned in those properties are applied by calling corresponding getters and setters . If the property itself is a bean then that bean will be instatiated using java ref api and coreeponding properties will be set . Once this is done if the Bean implements BeanNameAware , setBeanName method will be called by passing the Name of the Bean . If Bean implements BeanClassLoaderAware then the setBeanClassLoader() method will be called by passing the instance of classLoader

If the Bean implements BeanFactoryAware then the setBeanFactory() method will be called which will inturn take BeanFactory object instance . If there are any BeanProst process is associated with BeanFactory then postProcessBeforeInitialization() method will be called even before the properties for the bean are set .

If the bean implements InitializingBean interface then method afterPropertiesSet() method will be called which will be called once the properties in the bean are set . since we need to do something after properties are set. If the Bean definiton in the configuration xml contains inti-method then the values for the attribute will be rsolved by refering to the name and bean class properties and method will be called .
If there are any Bean post processes are associated with the bean factory then postProcessAfterInitialization() method will be called

If the Bean implments DisposableBean interface then destroy() method will be called and also container checks that configuration file contains any destroy-method property then the corresponding method will be called by using java reflect API .

So I hope provided good information to those who are reading this article but I just want to make it bit simple which will be very useful for those who want to read compact and precise information . so please check below step by step ifo whcih will be useful


A Spring Bean represents a POJO component performing some useful operation. All Spring Beans reside within a Spring Container also known as IOC Container. The Spring Framework is transparent and thereby hides most of the complex infrastructure and the communication that happens between the Spring Container and the Spring Beans. This section lists the sequence of activities that will take place between the time of Bean Instantiation and hand over of the Bean reference to the Client Application.





*******************************************************************************************

1. The Bean Container finds the definition of the Spring Bean in the Configuration file.
2. The Bean Container creates an instance of the Bean using Java Reflection API.
3. If any properties are mentioned, then they are also applied. If the property itself is a Bean, then it is resolved and set.
4. If the Bean class implements the BeanNameAware interface, then the setBeanName() method will be called by passing the name of the Bean.
5. If the Bean class implements the BeanClassLoaderAware interface, then the method setBeanClassLoader() method will be called by passing an instance of the ClassLoader object that loaded this bean.
6. If the Bean class implements the BeanFactoryAware interface, then the method setBeanFactory() will be called by passing an instance of BeanFactory object.
7. If there are any BeanPostProcessors object associated with the BeanFactory that loaded the Bean, then the method postProcessBeforeInitialization() will be called even before the properties for the Bean are set.
8. If the Bean class implements the InitializingBean interface, then the method afterPropertiesSet() will be called once all the Bean properties defined in the Configuration file are set.
9. If the Bean definition in the Configuration file contains a 'init-method' attribute, then the value for the attribute will be resolved to a method name in the Bean class and that method will be called.
10. The postProcessAfterInitialization() method will be called if there are any Bean Post Processors attached for the Bean Factory object.
11. If the Bean class implements the DisposableBean interface, then the method destroy() will be called when the Application no longer needs the bean reference.
12. If the Bean definition in the Configuration file contains a 'destroy-method' attribute, then the corresponding method definition in the Bean class will be called.





*************************************************************************






Enter you DOB ,Time and Place

SEO Schemes

Comments