Bean life cycle in Spring

As the most popular and powerful lightweight framework for Java, Spring has been warmly welcomed by programmers. Accurate understanding of the Spring Bean life cycle is very necessary. We usually use ApplicationContext as Spring container. Here, we are also talking about the life cycle of the Bean in the ApplicationContext. In fact, the BeanFactory is similar, except that the processor needs to be registered manually.

1. Life cycle flow chart:

The complete life cycle of Spring Bean starts from the creation of the Spring container and ends when the Spring container destroys the bean, which contains a series of key points.

2. Classification of various interface methods

The complete life cycle of a bean goes through various method calls, which can be divided into the following categories:

1. Bean's own method: This includes the methods called by the Bean itself and the methods specified by the init-method and destroy-method of <bean> in the configuration file

2. Bean-level life cycle interface methods: This includes the methods of BeanNameAware, BeanFactoryAware, InitializingBean and DiposableBean interfaces

3. Container-level life cycle interface method: This includes two interface implementations, InstantiationAwareBeanPostProcessor and BeanPostProcessor, and their implementation classes are generally called "post-processors".

4. Factory post-processor interface methods: This includes AspectJWeavingEnabler, ConfigurationClassPostProcessor, CustomAutowireConfigurer and other very useful factory post-processor interface methods. Factory post processors are also container-level. Called immediately after the application context has assembled the configuration file.

 

Original link: http://www.cnblogs.com/zrtqsk/p/3735273.html

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325161083&siteId=291194637