Bean生命周期及回调
2021-05-12 11:07:05 10 举报
bean的声明周期,及其重要的回调
作者其他创作
大纲/内容
InstantiationAwareBeanPostProcessor#postProcessAfterInstantiation实例化后置处理器
@PreDestroy
AutowiredAnnotationBeanPostProcessor
AutowiredAnnotationBeanPostProcessor完成@Autowired、@Value、@Inject注解注入
CommonAnnotationBeanPostProcessor完成@Resource的注入
doCreateBean
preInstantiateSingletons
完成@PostContruct调用
invokeInitMethods
DisposableBeanAdapter#destroy
createBeanInstance
invokeAwareMethods
bean销毁
((BeanNameAware) bean).setBeanName(beanName);((BeanClassLoaderAware) bean).setBeanClassLoader(bcl);((BeanFactoryAware) bean).setBeanFactory(AbstractAutowireCapableBeanFactory.this);
分支一,如果在此过程,用户创建了代理类,就不在走之后的doCreateBean流程了
AbstractAutoProxyCreator创建AOP代理类
createBean
BeanPostProcessor#postProcessAfterInitialization
MergedBeanDefinitionPostProcessor#postProcessMergedBeanDefinition完成相关注解的解析
CommonAnnotationBeanPostProcessor完成@PostConstruct、@PreDestroy、@Resource的解析
InitializingBean#afterPropertiesSet
AutowiredAnnotationBeanPostProcessor完成@Autowired、@Value、@Inject注解的解析
@Bean中或者xml中配置的自定义初始化方法init-method
SmartInstantiationAwareBeanPostProcessor#determineCandidateConstructors查找合适的构造器
SmartInitializingSingleton#afterSingletonsInstantiated
BeanPostProcessor#postProcessAfterInitializationbean初始化后置处理器,最重要就是AOP代理类创建
BeanPostProcessor#postProcessBeforeInitializationbean初始化前置处理器
((EnvironmentAware) bean).setEnvironment(this.applicationContext.getEnvironment());((EmbeddedValueResolverAware) bean).setEmbeddedValueResolver(this.embeddedValueResolver);((ResourceLoaderAware) bean).setResourceLoader(this.applicationContext);((ApplicationEventPublisherAware) bean).setApplicationEventPublisher(this.applicationContext);((MessageSourceAware) bean).setMessageSource(this.applicationContext);((ApplicationContextAware) bean).setApplicationContext(this.applicationContext);
populateBean
@Bean或者xml中定义的默认销毁方法
getBean
DisposableBean#destroy
InstantiationAwareBeanPostProcessor#postProcessBeforeInstantiation实例化前置处理器
CommonAnnotationBeanPostProcessor
initializeBean
ApplicationContextAwareProcessor
InstantiationAwareBeanPostProcessor#postProcessProperties完成属性的注入
doGetBean
0 条评论
下一页