Spring bean in the life cycle?

Reference: https://www.cnblogs.com/kenshinobiy/p/4652008.html

Spring Bean life cycle is as follows:

1: Bean establishment:

Looking Bean container of definition information and an example.

2: Properties injection:

Dependency injection, Spring Bean all attributes in the configuration definition information Bean

3: BeanNameAware 的 setBeanName ():

If the Bean class has implemented org.springframework.beans.BeanNameAware interface calls the Bean plants setBeanName () method passing Bean's ID.

4:BeanFactoryAware的setBeanFactory():

If Bean class has achieved org.springframework.beans.factory.BeanFactoryAware interfaces, factory calls setBeanFactory () method passed in the factory itself.

5:BeanPostProcessors的ProcessBeforeInitialization()

If there org.springframework.beans.factory.config.BeanPostProcessors and Bean association, its postProcessBeforeInitialization () method will be will be called.

6:initializingBean的afterPropertiesSet():

If the Bean class has achieved the org.springframework.beans.factory.InitializingBean, performing his afterProPertiesSet () method

7: Bean definition file defined in init-method:

You can use "init-method" property set methods in the name e.g. Bean definition file:

 

If there is more than set, then execute this stage, will perform initBean () method

8:BeanPostProcessors的ProcessaAfterInitialization()

If there are any instances associated with the instance of BeanPostProcessors Bean, BeanPostProcessors instance is executed ProcessaAfterInitialization () method

At this time, Bean has application may be used, and will not be retained until it is used in a BeanFactory.

When the bean is no longer used, turn off the bean

9:DisposableBean的destroy()

When the container is closed, if the Bean class has implemented org.springframework.beans.factory.DisposableBean interface, perform his destroy () method

10: Bean definition file is defined destroy-method

When the container is closed, using the "destroy-method" attribute setting method definition file name in the Bean

 

Guess you like

Origin www.cnblogs.com/baizhuang/p/10954013.html