Spring Boot自動配置:AopAutoConfigration
概要
自動構成
この自動配置類は注釈によって自分が有効になった条件を表明しています.以下のクラスは 構成パラメータ
このパラメータが使用されていない場合、
なお、構成パラメータ は、 .発効時に注釈を使用する は、 .発効時に注釈を使用する 上記の分析から、 属性 ソースコード
ソースコードバージョン:spring-book-at configre-2.13.RELEASE Spring BenPostProcessor:AnnotationAwareAspect JAtoxyCreator
自動構成
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-class
値true
として理解される.JdkDynamicAutoProxyConfiguration
spring.aop.proxy-target-class
がfalse
であるときに有効となる@EnableAspectJAutoProxy(proxyTargetClass = false)
CglibAutoProxyConfiguration
spring.aop.proxy-target-class
がfalse
であるか、または欠落した場合に有効となる@EnableAspectJAutoProxy(proxyTargetClass = true)
AopAutoConfiguration
は主に以下の2つの構成パラメータを総合的に使用して、注釈@EnableAspectJAutoProxy
をどのように使用するかを決定することができる.spring.aop.auto
spring.aop.proxy-target-class
spring.aop.auto
がfalse
に設定されていない場合、@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 {
}
}
関連記事