AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext();
ac.refresh();
ac.register(CycleConfig.class);
Spring bean工厂的后置处理器流程图
ConfigrationClassPostProcessor.postProcessBeanDefinitionRegistry(处理流程图)
ConfigrationClassPostProcessor.postProcessBeanFactory 处理@Configuration
spring bean的后置处理器
getSingleton
getMergedLocalBeanDefinition
isSingleton
singletonFactory.getObject()
resolveBeanClass
第一次
InstantiationAwareBeanPostProcessor
这个接口
postProcessBeforeInstantiation(程序猿可以扩展,返回一个bean,然后就会实例化对应的bean
ConfigurationClassPostProcessor.ImportAwareBeanPostProcessor 什么都没有做
AnnotationAwareAspectJAutoProxyCreator 加入不需要代理的类或者已经被代理的类
CommonAnnotationBeanPostProcessor 什么也没有做
AutowiredAnnotationBeanPostProcessor 什么也没有做
第二次
SmartInstantiationAwareBeanPostProcessor determineCandidateConstructors
默认构造方法推断不出来,多个推断不出来,只有一个非默认可以推断出来
AutowiredAnnotationBeanPostProcessor determineCandidateConstructors推断构造方法
第三次
MergedBeanDefinitionPostProcessor postProcessMergedBeanDefinition
1.postProcessMergedBeanDefinition 处理@PostConstruct @PreDestroy @Resource加入缓存
1.postProcessMergedBeanDefinition 处理@Autowired @Vavlue @Inject缓存
判断是否支持循环依赖 put singletonFactories
第四次
InstantiationAwareBeanPostProcessor.postProcessAfterInstantiation
默认的什么也没有做
程序员可以扩展,比如不进行属性注入,直接返回
第五次
InstantiationAwareBeanPostProcessor postProcessProperties
CommonAnnotationBeanPostProcessor postProcessProperties resource属性注入
AutowiredAnnotationBeanPostProcessor postProcessProperties 注入@Autowired @Vavlue @Inject
pvs //程序员提供的 spring找出来的
applyPropertyValues(beanName, mbd, bw, pvs);
处理aware接口 BeanNameAware BeanClassLoaderAware BeanFactoryAware
第六次
postProcessBeforeInitialization
ApplicationContextAwareProcessor 处理aware接口
EnvironmentAware EmbeddedValueResolverAware ResourceLoaderAware
ApplicationEventPublisherAware MessageSourceAware ApplicationContextAware
CommonAnnotationBeanPostProcessor postProcessBeforeInitialization 处理@PostConstruct
invokeInitMethods
afterPropertiesSet
invokeCustomInitMethod xml配置的init方法
第七次
postProcessAfterInitialization
postProcessAfterInitialization 加入ApplicationListener
postProcessAfterInitialization 创建代理类
registerDisposableBeanIfNecessary
addSingleton(beanName, singletonObject)
所有bean的生命周期都完了后
SmartInitializingSingleton afterSingletonsInstantiated
EventListenerMethodProcessor afterSingletonsInstantiated
Spring bean的后置处理器
1.EventListenerMethodProcessor
postProcessBeanFactory 初始化eventListenerFactories
this.eventListenerFactories = factories;
afterSingletonsInstantiated 不清楚做什么的?
(prepareBeanFactory)
1.ApplicationContextAwareProcessor postProcessBeforeInitialization 处理Aware接口
2.ApplicationListenerDetector
postProcessAfterInitialization 加入ApplicationListener
postProcessBeforeDestruction
ConfigurationClassPostProcessor.postProcessBeanFactory
暂时不清楚干什么
3.ConfigurationClassPostProcessor.ImportAwareBeanPostProcessor
registerBeanPostProcessors
好像用处也不大
4.PostProcessorRegistrationDelegate.BeanPostProcessorChecker
registerBeanPostProcessors bd
5.AnnotationAwareAspectJAutoProxyCreator
postProcessBeforeInstantiation
把不需要代理的类放入advisedBeans getCustomTargetSource在springboot中看有没有用到 目前是没有用到 暂时不知道什么意思
postProcessAfterInitialization 创建代理类
6.CommonAnnotationBeanPostProcessor(处理的注解:PostConstruct,PreDestroy,WebServiceRef,EJB,Resource)
1.postProcessMergedBeanDefinition 处理@PostConstruct @PreDestroy @Resource加入缓存
2.postProcessProperties resource属性注入
3.postProcessBeforeInitialization @PostConstruct
4.postProcessBeforeDestruction @PreDestroy
7.AutowiredAnnotationBeanPostProcessor
1.postProcessMergedBeanDefinition 处理@Autowired @Vavlue @Inject缓存
2.determineCandidateConstructors 推断构造方法
3.postProcessProperties 注入@Autowired @Vavlue @Inject
registerBeanPostProcessors 直接add进去的
8.ApplicationListenerDetector