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

Source: Internet
Author: User
Tags ocaml

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

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.