spring bean的加载过程

来源:互联网 发布:linux jdk 降级 编辑:程序博客网 时间:2024/06/05 19:33
1.初始化bean
2.依赖注入bean的所有属性
3.判断bean是否实现了BeanNameAware接口,调用setBeanName()方法获取xml配置文件中该bean的id
4.判断bean是否实现了BeanFactoryAware接口,调用setBeanFactory()方法获取实例化该bean的工厂实例的引用
5.判断bean‘是否实现了ApplicationContext接口,调用setApplicationContext()方法获取applicationContext容器实例
6.判断bean是否实现了BeanPostProcesser接口,调用预初始化方法
7.判断bean是否实现了initlizalingBean接口,调用初始化方法
8.调用xml中配置的init-method方法

9.判断bean是否实现了BeanPostProcesser接口,调用后初始化方法

比如:

1.RequiredAnnotationBeanPostProcessor是Spring中的后置处理用来验证被@Required 注解的bean属性是否被正确的设置了

2.AutowiredAnnotationBeanPostProcessor是Spring中的后置处理用来对 @Autowired 进行解析,自动装配

10.bean创建完成,直至容器销毁
11.判断bean是否实现了destoryXXX接口,调用derstory方法
12.调用xml中配置的destory-method方法
原创粉丝点击