Spring 5.x Source trip forty-two AOP of @EnableAspectJAutoProxy
What did EnableAspectJAutoProxy comment
This annotation is the key to open the AOP proxy, he is not really the key attributes inside the open, proxyTargetClass
but can either decide to use CGLIB
it. The real decision can proxy is AspectJAutoProxyRegistrar.class
.
AspectJAutoProxyRegistrar Acting Registrar
He is a ImportBeanDefinitionRegistrar
expansion, we have talked about earlier, you can sign up for a bean
definition.
class AspectJAutoProxyRegistrar implements ImportBeanDefinitionRegistrar {
/**
* Register, escalate, and configure the AspectJ auto proxy creator based on the value
* of the @{@link EnableAspectJAutoProxy#proxyTargetClass()} attribute on the importing
* {@code @Configuration} class.
*/
@Override
public void registerBeanDefinitions(
AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
AopConfigUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(registry);
AnnotationAttributes enableAspectJAutoProxy =
AnnotationConfigUtils.attributesFor(importingClassMetadata, EnableAspectJAutoProxy.class);
if (enableAspectJAutoProxy != null) {
if (enableAspectJAutoProxy.getBoolean("proxyTargetClass")) {
AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry);
}
if (enableAspectJAutoProxy.getBoolean("exposeProxy")) {
AopConfigUtils.forceAutoProxyCreatorToExposeProxy(registry);
}
}
}
}
What time of registration into it, in fact, in front also say that in class configuration parsing, after verification, were bean
registered when loaded into a defined, we take a look back just great.
Configuration classes
My configuration class:
@Configuration
@EnableAspectJAutoProxy
public class MyConfig {
}
Resolution Configuration class
ConfigurationClassPostProcessor
The processConfigBeanDefinitions
method.
ConfigurationClassParser
The doProcessConfigurationClass
middle:
First getImports
will be comments, and the comments of the parent Import
value of the notes come fully loaded:
So put AspectJAutoProxyRegistrar
to find out.
Then processImports
for the ImportBeanDefinitionRegistrar
type of treatment.
Then instantiated, then placed in the ConfigurationClass
in importBeanDefinitionRegistrars
the, behind the ready to load bean
defined by time.
Load bean definitions
ConfigurationClassBeanDefinitionReader
The loadBeanDefinitionsForConfigurationClass
last line:
is to call ImportBeanDefinitionRegistrar
the registerBeanDefinitions
method:
registerBeanDefinitions
In fact, we created AnnotationAwareAspectJAutoProxyCreator
a bean
definition, and then set the property.
@Override
public void registerBeanDefinitions(
AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
AopConfigUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(registry);
AnnotationAttributes enableAspectJAutoProxy =
AnnotationConfigUtils.attributesFor(importingClassMetadata, EnableAspectJAutoProxy.class);
if (enableAspectJAutoProxy != null) {
if (enableAspectJAutoProxy.getBoolean("proxyTargetClass")) {
AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry);
}
if (enableAspectJAutoProxy.getBoolean("exposeProxy")) {
AopConfigUtils.forceAutoProxyCreatorToExposeProxy(registry);
}
}
}
It is to create an internal bean definitions and registration:
next time tell AnnotationAwareAspectJAutoProxyCreator
what it is.
Well, here today, we hope to help study and understand, do not spray the Great God see, understand only their own learning, limited capacity, please excuse.