現在、XML 機能を使用して Spring の AOP をテストしていますが、機能させることができません。
編集:この問題は、メソッドがクラスのコンストラクターから呼び出された場合にのみ発生します。
私のapplicationContext.xml:
<beans xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<aop:aspectj-autoproxy/>
<bean id="aopClass" class="hu.viper.aoptest.AopClass"/>
<bean id="mainClass" class="hu.viper.aoptest.MainClass"/>
<aop:config>
<aop:aspect ref="aopClass">
<aop:pointcut id="pointCutBefore" expression="execution(* hu.viper.aoptest.MainClass.hello(..))"/>
<aop:before method="writeAOP" pointcut-ref="pointCutBefore"/>
</aop:aspect>
</aop:config>
</beans>
私の MainClass.java:
package hu.viper.aoptest;
public class MainClass {
public MainClass() {
this.hello();
}
public void hello() {
System.out.println("HELLO WORLD");
}
}
私のAopClass.java:
package hu.viper.aoptest;
import org.aspectj.lang.JoinPoint;
public class AopClass {
public void writeAOP(JoinPoint joinPoint) {
System.out.println("This is the AOP message!");
}
}
それは完璧にビルドされ、実行すると、netbeans の GlassFish 出力に "HELLO WORLD" が 2 回出力されますが (2 回理由はわかりません)、AOP メッセージは出力されません。私のコードの問題は何ですか?