Spring 源码 -BeanFactory 创建 Bean
父级接口:
BeanFactory
The root interface for accessing a Spring bean container.
子级接口:
HierarchicalBeanFactory
Sub-interface implemented by bean factories that can be part of a hierarchy.
ConfigurationBeanFactory
Configuration interface to be implemented by most bean factories. Provides facilities to configure a bean factory, in addition to the bean factory client methods in the BeanFactory interface.
AutowireCapableBeanFactory
Interface to be implemented by bean factories that are capable of autowiring.
抽象实现类:
AbstractBeanFactory
Abstract base class for BeanFactory implementations, providing the full capabilities of the ConfigurableBeanFactory SPI
AbstractAutowireCapableBeanFactory
Abstract bean factory superclass that implements default bean creation, with the full capabilities specified by the RootBeanDefinition class. Implements the AutowireCapableBeanFactoryinterface in addition to AbstractBeanFactory's createBean method.
层级关系:
核心方法:
Standard Bean Lifecycle:
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 {@code setBeanName}
* BeanClassLoaderAware's {@code setBeanClassLoader}
* BeanFactoryAware's {@code setBeanFactory}
* EnvironmentAware's {@code setEnvironment}
* EmbeddedValueResolverAware's {@code setEmbeddedValueResolver}
* ResourceLoaderAware's {@code setResourceLoader}
* (only applicable when running in an application context)
* ApplicationEventPublisherAware's {@code setApplicationEventPublisher}
* (only applicable when running in an application context)
* MessageSourceAware's {@code setMessageSource}
* (only applicable when running in an application context)
* ApplicationContextAware's {@code setApplicationContext}
* (only applicable when running in an application context)
* ServletContextAware's {@code setServletContext}
* (only applicable when running in a web application context)
* {@code postProcessBeforeInitialization} methods of BeanPostProcessors
* InitializingBean's {@code afterPropertiesSet}
* a custom init-method definition
* {@code postProcessAfterInitialization} methods of BeanPostProcessors
On shutdown of a bean factory, the following lifecycle methods apply:
* {@code postProcessBeforeDestruction} methods of DestructionAwareBeanPostProcessors
* DisposableBean's {@code destroy}
* a custom destroy-method definition
评论