Suppose beanfactory in order to generate and manage beans, a bean from inception to destruction. It will run through several stages.
As far as I know, generic beans are included in the life cycle: Set, initialize, use phase, four core phases destroyed.
1, the establishment of @Bean
The bean definition file is read by beanfactory and the individual bean instances are generated.
2. Initialize @ attribute Injection
Run related 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
Define Init-method 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. is to run the Initbean method.
@BeanPostProcessors of Processaafterinitialization ()
Assume that there is no beanpostprocessors instance associated with the bean instance. The Processaafterinitialization () method of the Beanpostprocessor instance is run.
4. Destruction of @DisposableBean Destroy ()
Container Close Org.springframework.beans.factory.DisposableBean
Define Destroy-method in @Bean definition file
<bean id="helloBean"class="org.bearfly.bean.HelloBean" destroy-method="destroyBean">
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
A good memory is better than a bad pen. 85-spring3 Learning (6)-beanfactory in bean life cycle