AOP(アスペクトオリエントプログラミング)、アスペクト指向プログラミング、オブジェクト指向プログラミングはOOPの補数です。オブジェクト指向プログラミングのプログラムの観点から動的指向プログラミングが実行されて、ビューの静的ポイントからプログラムの構造を考慮することです。
AOPの底部は、動的プロキシモードを使用して達成されます。動的プロキシCGLIBで、JDKの動的プロキシ:二つの薬剤を使用します。JDK動的プロキシは、インターフェース志向、CGLIBインターフェイスを実装し、インタフェースを実装することができないのいずれかです。(私は、動的プロキシの導入は動的プロキシ上で見ることができることを知りません)
プログラミング指向の、ビジネス・ロジックは、主要なビジネスロジックにインプラントAOPコンテナ部の機能を使用して、断面内にカプセル化されます。サービスロジック意味CROSS-と呼ばれる:一般、メインサービスロジックに依存しないコードで、このようなセキュリティチェック、トランザクションログなど。
@Aspect関数定義は、カット点接点を使用することができる、我々は、複合体を得るために、カット点の接線小数点演算を確認するために、論理演算子を使用することができ、接点部を再利用するために、我々は他のカットオフポイントに名前を付けることができます場所は、接点の定義を引用していました。接触点に一致する複数の接続点は、織りシーケンスの問題を考えるときには、加えて、1つの重要な問題は、さらに、接続点情報アクセスコンテキストを強化する方法です。
1、@アスペクト
<AOP:AspectJの-オートプロキシ/定義XMLで >、
http://www.springframework.org/schema/aop/spring-aop-3.0.xsdに定義されています
- <xsd:element name="aspectj-autoproxy">
- <xsd:annotation>
- <xsd:documentation source="java:org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator">
- <![CDATA[
Enables the use of the @AspectJ style of Spring AOP.
]]>
</xsd:documentation>
</xsd:annotation>
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="include" type="includeType" minOccurs="0" maxOccurs="unbounded">
- <xsd:annotation>
- <xsd:documentation>
- <![CDATA[
Indicates that only @AspectJ beans with names matched by the (regex)
pattern will be considered as defining aspects to use for Spring autoproxying.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
- <xsd:attribute name="proxy-target-class" type="xsd:boolean" default="false">
- <xsd:annotation>
- <xsd:documentation>
- <![CDATA[
Are class-based (CGLIB) proxies to be created? By default, standard
Java interface-based proxies are created.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
- <xsd:attribute name="expose-proxy" type="xsd:boolean" default="false">
- <xsd:annotation>
- <xsd:documentation>
- <![CDATA[
Indicate that the proxy should be exposed by the AOP framework as a
ThreadLocal for retrieval via the AopContext class. Off by default,
i.e. no guarantees that AopContext access will work.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
1.1登録
org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator
次のように継承は、以下のとおりです。
1.2解決プロセス
AspectJAutoProxyBeanDefinitionParser.java#パース()方法
public BeanDefinition parse(Element element, ParserContext parserContext) {
AopNamespaceUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(parserContext, element);
extendBeanDefinition(element, parserContext);
return null;
}
登録プロセス:
public static void registerAspectJAnnotationAutoProxyCreatorIfNecessary(
ParserContext parserContext, Element sourceElement) {
BeanDefinition beanDefinition = AopConfigUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(
parserContext.getRegistry(), parserContext.extractSource(sourceElement));
useClassProxyingIfNecessary(parserContext.getRegistry(), sourceElement);
registerComponentIfNecessary(beanDefinition, parserContext);
}
実装クラスを呼び出します。
public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry, Object source) {
return registerOrEscalateApcAsRequired(AnnotationAwareAspectJAutoProxyCreator.class, registry, source);
}
1.3特定の実装クラス:postProcessAfterInitialization()メソッドAbstractAutoProxyCreator
DefaultAopProxyFactory#createAopProxy()メソッド
@Override
public AopProxy createAopProxy(AdvisedSupport config) throws AopConfigException {
if (config.isOptimize() || config.isProxyTargetClass() || hasNoUserSuppliedProxyInterfaces(config)) {
Class<?> targetClass = config.getTargetClass();
if (targetClass == null) {
throw new AopConfigException("TargetSource cannot determine target class: " +
"Either an interface or a target is required for proxy creation.");
}
if (targetClass.isInterface()) {
return new JdkDynamicAopProxy(config);
}
return new ObjenesisCglibAopProxy(config);
}
else {
return new JdkDynamicAopProxy(config);
}
}
デフォルトのJDK自身の機関は、CGLIBの方法があります。