Spring源码解析---AOP
程序员文章站
2022-07-12 14:58:42
...
动态AOP自定义标签
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。
代理对象生成过程的时序图如下:
代理对象调用的过程
以JdkDynamicAopProxy为例:
上一篇: JumpServer 堡垒机安装笔记
下一篇: 从输入域名,到拿到首页的所有细节过程