spring BeanFactory解析

版权声明:版权归作者所有 https://blog.csdn.net/yulin959/article/details/80977872

BeanFactory是spring容器的根容器,定义和约定了获取对象.定义了spring管理的对象的生命周期;

生命周期如下:

    

Bean factory implementations should support the standard bean lifecycle interfaces as far as possible. The full set of initialization methods and their standard order is:

  1. BeanNameAware's setBeanName
  2. BeanClassLoaderAware's setBeanClassLoader
  3. BeanFactoryAware's setBeanFactory
  4. EnvironmentAware's setEnvironment
  5. EmbeddedValueResolverAware's setEmbeddedValueResolver
  6. ResourceLoaderAware's setResourceLoader (only applicable when running in an application context)
  7. ApplicationEventPublisherAware's setApplicationEventPublisher (only applicable when running in an application context)
  8. MessageSourceAware's setMessageSource (only applicable when running in an application context)
  9. ApplicationContextAware's setApplicationContext (only applicable when running in an application context)
  10. ServletContextAware's setServletContext (only applicable when running in a web application context)
  11. postProcessBeforeInitialization methods of BeanPostProcessors
  12. InitializingBean's afterPropertiesSet
  13. a custom init-method definition
  14. postProcessAfterInitialization methods of BeanPostProcessors

On shutdown of a bean factory, the following lifecycle methods apply:

  1. postProcessBeforeDestruction methods of DestructionAwareBeanPostProcessors
  2. DisposableBean's destroy
  3. a custom destroy-method definition

与BeanFactory名称相似的是FactoryBean是一个Bean工厂,在AOP中大量使用.FactoryBean是一个Bean对象,由它创建的一般对象不会返回自身对象,是返回一个创建的一个其他对象,如果要获取本身对象,则需要getBean时加&符号.

猜你喜欢

转载自blog.csdn.net/yulin959/article/details/80977872