接上一篇https://blog.csdn.net/qq_26437925/article/details/144865082
探究一下beanPostProcessors
怎么加进来的
目录
- 首先register(annotatedClasses);后添加了重要的beanDefinition: ConfigurationClassPostProcessor
- `invokeBeanFactoryPostProcessors(beanFactory);`执行后添加了ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor
- 具体是`invokeBeanFactoryPostProcessors(registryProcessors, beanFactory);`执行后添加的
- `registerBeanPostProcessors(beanFactory);`执行完继续添加了几个BeanPostProcessor
- onRefresh()方法前有7个BeanPostProcessor
首先register(annotatedClasses);后添加了重要的beanDefinition: ConfigurationClassPostProcessor
invokeBeanFactoryPostProcessors(beanFactory);
执行后添加了ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor
具体是invokeBeanFactoryPostProcessors(registryProcessors, beanFactory);
执行后添加的
执行了ConfigurationClassPostProcessor的postProcessBeanFactory方法
/*** Prepare the Configuration classes for servicing bean requests at runtime* by replacing them with CGLIB-enhanced subclasses.*/
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {int factoryId = System.identityHashCode(beanFactory);if (this.factoriesPostProcessed.contains(factoryId)) {throw new IllegalStateException("postProcessBeanFactory already called on this post-processor against " + beanFactory);}this.factoriesPostProcessed.add(factoryId);if (!this.registriesPostProcessed.contains(factoryId)) {// BeanDefinitionRegistryPostProcessor hook apparently not supported...// Simply call processConfigurationClasses lazily at this point then.processConfigBeanDefinitions((BeanDefinitionRegistry) beanFactory);}enhanceConfigurationClasses(beanFactory);beanFactory.addBeanPostProcessor(new ImportAwareBeanPostProcessor(beanFactory));
}
进行代理后,添加了BeanPostProcessor,new了一个ImportAwareBeanPostProcessor
registerBeanPostProcessors(beanFactory);
执行完继续添加了几个BeanPostProcessor
多加了4个:
- AutowiredAnnotationBeanPostProcessor
- CommonAnnotationBeanPostProcessor
- AnnotationAwareAspectJAutoProxyCreator
- PostProcessorRegistrationDelegate$BeanPostProcessorChecker
内置的3个BeanPostProcessor ,加上new出来的BeanPostProcessorChecker
直接实例化了BeanPostProcessor:
onRefresh()方法前有7个BeanPostProcessor
这些BeanPostProcessor为后续的bean实例化服务
如 https://blog.csdn.net/qq_26437925/article/details/144796129: AutowiredAnnotationBeanPostProcessor 就能完成对@Autowired的处理