Spring的Bean加载过程

在加载Bean时需要经历11个步骤

  1. instantiate bean 对象实例化
  2. 属性注入
  3. 如果Bean 实现了BeanNameAware 执行setBeanName 方法
  4. 如果Bean实现了BeanFactoryAware 或者ApplicationContextAware 可执行设置工厂setBeanFactory 方法或者上下文对象setApplicationContext方法
  5. 如果Bean实现了BeanPostProcess 执行postProcessBeforeInitialization方法
  6. 如果Bean实现了InitalizingBean 执行afterProperties方法
  7. 调用< bean init-method=" ···· " >所指定的方法
  8. 如果Bean实现了BeanPostProcess 执行postProcessAfterInitialization方法
  9. 执行处理业务代码
  10. 如果实现了DisposableBean执行destroy方法
  11. 调用 < bean destroy-method=" ···· " >所指定的方法

猜你喜欢

转载自blog.csdn.net/li_ya_kun/article/details/83415814