Life Cycle Management of a Spring Bean

匿名 (未验证) 提交于 2019-12-03 00:34:01

  1. The Bean Container finds the definition of the Spring Bean in the Configuration file.

---------------------在第2步之前还会检测是否实现了InstantiationAwareBeanPostProcessors,(源码注释:Give BeanPostProcessors a chance to return a proxy instead of the target bean instance),如果此postProcessBeforeInstantiation不返回null,后续doCreateBean方法中的aware方法,ini方法都不会执行----------

  1. The Bean Container creates an instance of the Bean using Java Reflection API.
  2. If any properties are mentioned, then they are also applied. If the property itself is a Bean, then it is resolved and set.

------------------------当执行第四步骤时候,bean在JVM中已经实例化,且完成了spring初始化的属性注入--------------

  1. BeanNameAwaresetBeanName()method will be called by passing the name of the Bean. (bean感知自己在factory中的名字)
  2. BeanClassLoaderAwaresetBeanClassLoader()ClassLoader
  3. BeanFactoryAwaresetBeanFactory()BeanFactory(bean感知自己所在在的factory)
  4. BeanPostProcessorsBeanFactorypostProcessBeforeInitialization()
  5. InitializingBeanafterPropertiesSet()
  6. 'init-method'
  7. postProcessAfterInitialization()
  8. DisposableBeandestroy()
  9. 'destroy-method'attribute, then the corresponding method definition in the Bean class will be called.








标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!