If you use Beanfactory to build and manage beans, a bean will go through several stages of execution, from build to destroy.
I personally understand that the general bean life cycle mainly includes: Build, initialize, use phase, destroy four core phases.
1, the establishment of @Bean
The bean definition file is read by beanfactory and the individual bean instances are generated.
2. Initialize @ attribute Injection
Executes the associated Bean property Dependency Injection
@BeanNameAware of Setbeanname ()
Org.springframework.beans.factory.BeanNameAware
@BeanFactoryAware of Setbeanfactory ()
Org.springFramework.beans.factory.BeanFactoryAware
@BeanPostProcessors of Processbeforeinitialization ()
Org.springFramework.beans.factory.config.BeanPostProcessors
@InitializiongBean of Afterpropertiesset ()
Org.springframework.beans.factory.InitializingBean
Init-method defined in @Bean definition file
Use the "INIT-METHD" to set method name e.g:
<bean id="helloBean"class="org.bearfly.bean.HelloBean" init-method="initBean">
When the code runs to this stage, the Initbean method is executed.
@BeanPostProcessors of Processaafterinitialization ()
If any of the Beanpostprocessors instances are associated with the bean instance, the Processaafterinitialization () method of the Beanpostprocessor instance is executed.
4. Destruction of @DisposableBean Destroy ()
Container Close Org.springframework.beans.factory.DisposableBean
Destroy-method defined in @Bean definition file
<bean id="helloBean"class="org.bearfly.bean.HelloBean" destroy-method="destroyBean">
A good memory is better than a bad pen 85-spring3 learn (6) The life cycle of a bean in-beanfactory