publicclassAopNamespaceHandlerextendsNamespaceHandlerSupport { @Override publicvoidinit() { // In 2.0 XSD as well as in 2.1 XSD. registerBeanDefinitionParser("config", newConfigBeanDefinitionParser()); //对aspectj-autoproxy配置的解析类 registerBeanDefinitionParser("aspectj-autoproxy", newAspectJAutoProxyBeanDefinitionParser()); registerBeanDefinitionDecorator("scoped-proxy", newScopedProxyBeanDefinitionDecorator()); // Only in 2.0 XSD: moved to context namespace as of 2.1 registerBeanDefinitionParser("spring-configured", newSpringConfiguredBeanDefinitionParser()); } }
我们知道,当解析到 <aop:aspectj-autoproxy /> 注解时,会调用 AspectJAutoProxyBeanDefinitionParser 的 parse方法,关于自定义注解的解析内容之前 IoC 的文章介绍过了。
/** * Indicate whether subclass-based (CGLIB) proxies are to be created as opposed * to standard Java interface-based proxies. The default is {@code false}. * * true * 1、目标对象实现了接口 – 使用CGLIB代理机制 * 2、目标对象没有接口(只有实现类) – 使用CGLIB代理机制 * * false * 1、目标对象实现了接口 – 使用JDK动态代理机制(代理所有实现了的接口) * 2、目标对象没有接口(只有实现类) – 使用CGLIB代理机制 */ booleanproxyTargetClass()defaultfalse;
/** * Indicate that the proxy should be exposed by the AOP framework as a {@code ThreadLocal} * for retrieval via the {@link org.springframework.aop.framework.AopContext} class. * Off by default, i.e. no guarantees that {@code AopContext} access will work. * @since 4.3.1 */ booleanexposeProxy()defaultfalse;
/** * 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 publicvoidregisterBeanDefinitions( AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {