*********************************************************************************************************
@EnableAspectJAutoProx 这个是什么类
@Import(AspectJAutoProxyRegistrar.class) 导入组件AspectJAutoProxyRegistrar这个组件又是什么?
@class AspectJAutoProxyRegistrar implements ImportBeanDefinitionRegistrar 接口importBeanDDefinitionRegistrar
@AopConfigUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(registry);
*AnnotationAwareAspectJAutoProxyCreator//给容器注入一个自动代理创建器 //这个又是什么呢?
*********************************************************************************************************
部分源码
*********************************************************************************************************
private static BeanDefinition registerOrEscalateApcAsRequired(Class<?> cls, BeanDefinitionRegistry registry, Object source) {
Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
if (registry.containsBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME)) {
BeanDefinition apcDefinition = registry.getBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME);
if (!cls.getName().equals(apcDefinition.getBeanClassName())) {
int currentPriority = findPriorityForClass(apcDefinition.getBeanClassName());
int requiredPriority = findPriorityForClass(cls);
if (currentPriority < requiredPriority) {
apcDefinition.setBeanClassName(cls.getName());
}
}
return null;
}
RootBeanDefinition beanDefinition = new RootBeanDefinition(cls);
beanDefinition.setSource(source);
beanDefinition.getPropertyValues().add("order", Ordered.HIGHEST_PRECEDENCE);
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
registry.registerBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME, beanDefinition);
return beanDefinition;
}
*********************************************************************************************************
一下类的extends
AnnotationAwareAspectJAutoProxyCreator
-> AspectJAwareAdvisorAutoProxyCreator
->AbstractAdvisorAutoProxyCreator
->AbstractAutoProxyCreator
->ProxyConfig
->implements SmartInstantiationAwareBeanPostProcessor, BeanClassLoaderAware, BeanFactoryAware,Ordered, AopInfrastructureBean
(SmartInstantiationAwareBeanPostProcessor,关注后置处理器(在bean初始化完成前后做事情),自动装配BeanFactoryAware)
*********************************************************************************************************
- AbstractAutoProxyCreator/有后置处理器的逻辑
setBeanFactory/postProcessBeforeInstantiation[]/ postProcessAfterInitialization
- AbstractAdvisorAutoProxyCreator/@Override setBeanFactory()/initBeanFactory
- AnnotationAwareAspectJAutoProxyCreator/initBeanFactory()
*********************************************************************************************************
new AnnotationConfigApplication
1、传入配置类,创建ioc容器
2、注册配置类,调用refresh()刷新容器;
3、AbstractApplicationContext/
// Register bean processors that intercept bean creation.
//注册拦截bean创建的bean处理器
registerBeanPostProcessors(beanFactory); 注册bean的后置处理器方便bean的创建
PostProcessorRegistrationDelegate
registerBeanPostProcessors
1)、现获取IOC容器已经定义了的需要创建对象的所有BeanPostProcessor
【
public static void registerBeanPostProcessors(
ConfigurableListableBeanFactory beanFactory, AbstractApplicationContext applicationContext) {
String[] postProcessorNames = beanFactory.getBeanNamesForType(BeanPostProcessor.class, true, false);//这里是拿到所有的处理器
】
2)、给容器中加别的BeanPostProcessors
3)、优先注册实现了PriorityOrdered接口的BeanPostProcessor
4)、再给容器中注册实现了Ordered接口的BeanPostProcessor
5)、注册没实现以后先接口的PostProcessor
6)、注册PostProcessor,实际上就是创建PostProcessor对象,保存在容器中
创建internalAutoProxyCreator的BeanPostProcessor[AnnotationAwareAspectJAutoProxyCreator]
1)、创建Bean的实例
2)、populateBean;给bean的各种属性赋值
3)、internalzBean;初始化bean
*********************************************************************************************************未完待续记录中