概述
Bean的生命周期的11个步骤:
1.instantiate bean对象实例化
2.populate properties 封装属性
(第三步和第四步是让自己设计的bean了解spring容器)
3.如果Bean实现BeanNameAware 执行 setBeanName
4.如果Bean实现BeanFactoryAware 或者 ApplicationContextAware 设置工厂 setBeanFactory 或者上下文对象 setApplicationContext
(第五步和第八步实现自 BeanPostProcessor,可以用来增强 Bean)
5.如果存在类实现 BeanPostProcessor(后处理Bean) ,执行postProcessBeforeInitialization
6.如果Bean实现InitializingBean 执行 afterPropertiesSet
7.调用<bean init-method="init"> 指定初始化方法 init
8.如果存在类实现 BeanPostProcessor(处理Bean) ,执行postProcessAfterInitialization
9.执行业务处理
10.如果Bean实现 DisposableBean 执行 destroy
11.调用<bean destroy-method="customerDestroy"> 指定销毁方法 customerDestroy
在CustomerService类的add方法之前进行权限校验?
------------------------------具体体现分割线----------------------------------------------------------------
1,bean instantiate 对象实例化

2,populate properties 封装属性


3,如果 Bean 实现了 BeanNameAware, 则执行 setBeanName;


4,如果 Bean 实现 BeanFactoryAware 或 ApplicationContextAware, 则执行设置工厂 setBeanFactory 或 设置上下文对象setApplicationContext


5,如果存在类实现了 BeanPostProcessor, 则执行 postProcessorBeforeInitialization

6,如果 Bean 实现了 InitializingBean 则执行 afterPropertiesSet

7,执行配置文件中 Bean 指定的初始化方法 <init-method="methodName">

8,如果存在类实现了 BeanPostProcessor, 则执行 postProcessorAfterInitialization

9,用户自定义业务方法

10,如果 Bean 实现了 DisposableBean,调用 destory 方法.


11,调用配置文件中用户自定义的摧毁方法

转载于:https://www.cnblogs.com/harryper/p/6853473.html
最后
以上就是怕孤独凉面为你收集整理的spring 中类完整的生命周期的全部内容,希望文章能够帮你解决spring 中类完整的生命周期所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复