Spring的生命周期
其他
2018-05-07 02:07:06
阅读次数: 4
Spring的生命周期
- 1,调用Bean的构造函数(或者工厂方法)实例化Bean.
- 2,对Bean的成员变量赋值.
- 3,如果Bean实现了BeanNameAware,调用Bean的setBeanName方法.
- 4,如果Bean实现了BeanFactoryAware,调用Bean的setBeanFactory方法.
- 5,如果Bean实现了ApplicationContextAware,调用Bean的setApplicationContext方法.
- 6,如果容器中配置了BeanPostProcessor,调用BeanPostProcessor的postProcessBeforeInitialization方法(如果有多个BeanPostProcessor,调用每一个BeanPostProcessor的postProcessBeforeInitialization方法).
- 6,如果Bean实现了InitializingBean,调用Bean的afterPropertiesSet方法.
- 7,如果Bean配置了init-method方法,调用init-method配置的Bean方法.
- 8,如果容器中配置了BeanPostProcessor,调用BeanPostProcessor的postProcessAfterInitialization方法.(如果有多个BeanPostProcessor,调用每一个BeanPostProcessor的postProcessAfterInitialization方法).
- 9,Bean处于可以使用的状态.
- 10,Spring容器关闭.
- 11,如果Bean实现了DisposableBean,调用Bean的destroy方法.
- 12,如果Bean配置了destroy-method方法,调用destroy-method配置的Bean的方法.
转载自my.oschina.net/u/2302503/blog/1579730