Spring源码解析---AOP

动态AOP自定义标签

动态AOP自定义标签

"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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);//注册BeanDefinition
return beanDefinition;
}

代理对象生成的过程

AbstractAutoProxyCreator是一种InstantiationAwareBeanPostProcessor,其url图如下,其有效的方法是:postProcessBeforeInstantiation,postProcessAfterInitialization。

enter description here

"

代理对象生成过程的时序图如下:

enter description here

"

代理对象调用的过程

以JdkDynamicAopProxy为例:

enter description here

"

以下博客写得很好:
https://my.oschina.net/u/2377110/blog/1507532