bean生命周期
1.spring对bean进行初始化
2.spring填充bean的属性
3.如果bean实现BeanNameAware接口,调用setBeanName()
4.如果bean实现BeanFactoryAware接口,调用setBeanFactory()
5.如果bean实现ApplicationContextAware接口,调用setApplicationContext()
6.如果bean实现BeanPostProcessor接口,调用postProcessBeforeInitialization()
7.如果bean实现InitializingBean接口,调用afterPropertiesSet()。bean使用init-method声明初始化方法,该方法也会执行
8.如果bean实现BeanPostProcess接口,调用postProcessAfterInitialization()
9.此时bean准备就绪,可以使用了。他会一直留在内存中,直到应用上下文被销毁
10.如果bean实现DesposableBean接口,调用destroy()。同样bean使用destroy-method声明销毁方法,该方法也会执行
网友评论