3

私は次の構成を持っています:


@Aspect
public class MyAspect {

 @Around(@annotation(SomeAnnotation))
 public Object myMethod(ProceedingJoinPoint joinPoint) throws Throwable {
   System.out.println("Hello...");
 }
}

また、次の Bean 定義があります。

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
    <bean id="myAspect" class="MyAspect" />
</beans>

@SomeAnnotation実行時にアノテーション付きメソッドに動作が適用されていないことがわかります。理由はありますか?

どうも。

4

2 に答える 2

2

@SomeAnnoation を持つクラスが Spring コンテナーによって作成されていることを確認してください。Spring は、オブジェクトをラップするプロキシ クラスを作成することにより、コンテナーから取得されたクラスに AOP を適用します。次に、このプロキシ クラスは、そのオブジェクトのメソッドが呼び出される前後に Aspect を実行します。

よくわからない場合は、クラスを使用している場所にデバッグしてみてください。オブジェクトがクラスのインスタンスではなく、プロキシ オブジェクトであることがわかります。

于 2009-11-06T21:58:07.003 に答える