"简单介绍下Spring中Bean的生命周期?"

简单介绍下Spring中Bean的生命周期?

创建对象

  • 实例化(构造方法)
  • 依赖注入

初始化

  • 执行Aware接口回调
  • 执行 BeanPostProcessor.postProcessBeforeInitialization
  • 执行 InitializingBean 回调(先执行 @PostConstruct
  • 执行 BeanPostProcessor.postProcessAfterInitialization

使用对象

销毁对象

  • 执行 DisposableBean 回调(先执行 @PreDestory

其中创建对象和初始化都是在 AbstractAutowireCapableBeanFactory.doCreateBean() 方法里完成的。

PS:写作不易,如要转裁,请标明转载出处。
登录
注册
回顶部