版权声明:版权归作者所有 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:
- BeanNameAware's
setBeanName
- BeanClassLoaderAware's
setBeanClassLoader
- BeanFactoryAware's
setBeanFactory
- EnvironmentAware's
setEnvironment
- EmbeddedValueResolverAware's
setEmbeddedValueResolver
- ResourceLoaderAware's
setResourceLoader
(only applicable when running in an application context) - ApplicationEventPublisherAware's
setApplicationEventPublisher
(only applicable when running in an application context) - MessageSourceAware's
setMessageSource
(only applicable when running in an application context) - ApplicationContextAware's
setApplicationContext
(only applicable when running in an application context) - ServletContextAware's
setServletContext
(only applicable when running in a web application context) postProcessBeforeInitialization
methods of BeanPostProcessors- InitializingBean's
afterPropertiesSet
- a custom init-method definition
postProcessAfterInitialization
methods of BeanPostProcessors
On shutdown of a bean factory, the following lifecycle methods apply:
postProcessBeforeDestruction
methods of DestructionAwareBeanPostProcessors- DisposableBean's
destroy
- a custom destroy-method definition
与BeanFactory名称相似的是FactoryBean是一个Bean工厂,在AOP中大量使用.FactoryBean是一个Bean对象,由它创建的一般对象不会返回自身对象,是返回一个创建的一个其他对象,如果要获取本身对象,则需要getBean时加&符号.