- 实例化
通过发射实现:Constructor ctor = clazz.getDeclareConstructor();
Object obj = ctor.newInstance(); - 填充属性(populateBean();)
- 执行aware接口中需要实现的方法(aware接口存在的意义是:为了通过Spring中的Bean对象来获取对应容器中的相关属性,如beanName)
- BeanPostProcessor:before();
- init-method();
- BeanPostProcessor:before();
- 得到完整对象
- 进行销毁
详细查看Spring源码中:BeanFactory接口及注释,部分如下
`
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
- 该接口部分源码注释。