A good memory is better than a bad pen. 85-spring3 Learning (6)-beanfactory in bean life cycle

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.