Spring Boot自動配置:AopAutoConfigration


概要
自動構成AopAutoConfigurationクラスの主なタスクは、構成パラメータに従って注釈@EnableAspectJAutoProxyを使用することである.
この自動配置類は注釈によって自分が有効になった条件を表明しています.
  • 以下のクラスはclasspathに存在しなければならない.
  • EnableAspectJAutoProxy
  • Aspect
  • Advice
  • AnnotatedElement
  • 構成パラメータspring.aop.auto値はfalseではない.
    このパラメータが使用されていない場合、spring.aop.autoに相当する値はtrueである.
  • AopAutoConfigurationはまた、それぞれ対応する構成パラメータspring.aop.proxy-target-classの値がtrue/falseの2つのケースを含む.
    なお、構成パラメータspring.aop.proxy-target-classが設定されていない場合、この場合はspring.aop.proxy-target-classtrueとして理解される.
  • JdkDynamicAutoProxyConfiguration
  • は、spring.aop.proxy-target-classfalseであるときに有効となる
  • .
  • 発効時に注釈を使用する@EnableAspectJAutoProxy(proxyTargetClass = false)
  • CglibAutoProxyConfiguration
  • は、spring.aop.proxy-target-classfalseであるか、または欠落した場合に有効となる
  • .
  • 発効時に注釈を使用する@EnableAspectJAutoProxy(proxyTargetClass = true)
  • 上記の分析から、AopAutoConfigurationは主に以下の2つの構成パラメータを総合的に使用して、注釈@EnableAspectJAutoProxyをどのように使用するかを決定することができる.
  • spring.aop.auto
  • spring.aop.proxy-target-class
  • spring.aop.autofalseに設定されていない場合、@EnableAspectJAutoProxyは必ず使用される.@EnableAspectJAutoProxyが使用する効果は主にAspectJAutoProxyRegistrarを導入することである.AspectJAutoProxyRegistrarは、最終的にはAopConfigUtilsを介してAOPプロキシオブジェクト作成器beanをコンテナに登録する.
  • bean名称:org.springframework.aop.config.internalAutoProxyCreator
  • beanタイプ:AnnotationAwareAspectJAutoProxyCreator
  • 属性order:HIGHEST_PRECEDENCE
  • bean役:ROLE_INFRASTRUCTURE
  • ソースコード
    ソースコードバージョン:spring-book-at configre-2.13.RELEASE
    package org.springframework.boot.autoconfigure.aop;
    
    //    import  
    /**
     * org.springframework.boot.autoconfigure.EnableAutoConfiguration
     * Auto-configuration for Spring's AOP support. Equivalent to enabling
     * org.springframework.context.annotation.EnableAspectJAutoProxy in your
     * configuration.
     * 
     * The configuration will not be activated if spring.aop.auto=false. The
     * proxyTargetClass attribute will be true, by default, but can be
     * overridden by specifying spring.aop.proxy-target-class=false.
     *
     */
    @Configuration
    //          classpath    
    @ConditionalOnClass({ EnableAspectJAutoProxy.class, Aspect.class, Advice.class,
    		AnnotatedElement.class })
    //      spring.aop.auto           true             
    @ConditionalOnProperty(prefix = "spring.aop", name = "auto", havingValue = "true", matchIfMissing = true)
    public class AopAutoConfiguration {
    
    	@Configuration
    	@EnableAspectJAutoProxy(proxyTargetClass = false)
    	//       spring.aop.proxy-target-class         false    
    	@ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", 
    		havingValue = "false", matchIfMissing = false)
    	public static class JdkDynamicAutoProxyConfiguration {
    
    	}
    
        
    	@Configuration
    	@EnableAspectJAutoProxy(proxyTargetClass = true)
    	//       spring.aop.proxy-target-class             true        
    	@ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", 
    		havingValue = "true", matchIfMissing = true)
    	public static class CglibAutoProxyConfiguration {
    
    	}
    
    }
    
    関連記事
  • Spring BenPostProcessor:AnnotationAwareAspect JAtoxyCreator