spring BeanFactory接口是spring容器的根接口
下面是doc文档中的关于bean生命周期的全流程定义:
-
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
- @author Rod Johnson
- @author Juergen Hoeller
- @author Chris Beams
- @since 13 April 2001
- @see BeanNameAware#setBeanName
- @see BeanClassLoaderAware#setBeanClassLoader
- @see BeanFactoryAware#setBeanFactory
- @see org.springframework.context.ResourceLoaderAware#setResourceLoader
- @see org.springframework.context.ApplicationEventPublisherAware#setApplicationEventPublisher
- @see org.springframework.context.MessageSourceAware#setMessageSource
- @see org.springframework.context.ApplicationContextAware#setApplicationContext
- @see org.springframework.web.context.ServletContextAware#setServletContext
- @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization
- @see InitializingBean#afterPropertiesSet
- @see org.springframework.beans.factory.support.RootBeanDefinition#getInitMethodName
- @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization
- @see DisposableBean#destroy
- @see org.springframework.beans.factory.support.RootBeanDefinition#getDestroyMethodName