Spring生命周期

初始化和销毁

init在构造方法之前执行
destroy在applicationContext.close方法之后执行
ClassPathXmlApplicationContext才拥有close方法
两种方式
一是使用reflection
applicationContext.getClass() 获取反射对象
.getMethod(“close”) 获取反射对象的方法
.invoke(applicationContext) 使用applicationContext的close方法
二是直接取消多态
Spring生命周期
Spring生命周期

后处理Bean (实现BeanPostProcessor接口)

执行顺序:
new 对象()
before()
init()
after()
代理
addUser()
代理
destroy()
Spring生命周期
使用动态代理实现代理