我所有的junit测试都在eclipse中传递,但是当从控制台运行时,他们似乎为AJ类抛出了ClassNotFoundException RiskLogAspect.aj我可以验证在eclipse中这是正确编织并提供所需的功能。
我已经尝试将依赖项添加到我的项目中以确保一切正确。
我开始添加aspectj-maven-plugin
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
<phase>process-sources</phase>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<encoding>UTF8</encoding>
<source>1.6</source>
<target>1.6</target>
<aspects>
<includes>
<include>com.idna.riskprofile.RiskLogAspect</include>
</includes>
</aspects>
</configuration>
</execution>
</executions>
</plugin>
然后我添加了以下依赖项
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.7</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.7</version>
</dependency>
任何想法出了什么问题?
我正在运行maven 2.0.9以及jdK 1.6 update 21
更改了我的一些配置后,我注意到在控制台中我得到了以下“[Xlint:adviceDidNotMatch]”看起来它正在拿起我的课而不是正确应用切入点。
对于目标编译,它找到AJ文件并正确应用建议,对于测试 - 编译目标,它说Xlint:adviceDidNotMatch并抛出一半junit测试的类找不到异常。 从控制台:
[INFO] [aspectj:compile {execution: default}]
[INFO] Join point 'method-execution(java.lang.String com.idna.riskprofile.impl.RiskProfileEntryPointImpl.execute(com.idna.riskprofile.domain.RiskProfileRequest))' in Type 'com.idna.riskprofile.impl.RiskProfileEntryPointImpl' (RiskProfileEntryPointImpl.java:35) advised by around advice from 'com.idna.riskprofile.logging.aspects.RiskLogAspect' (RiskLogAspect.aj:35)
[INFO] [aspectj:test-compile {execution: default}]
[WARNING] advice defined in com.idna.riskprofile.logging.aspects.RiskLogAspect has not been applied [Xlint:adviceDidNotMatch]
[INFO] [resources:resources]
更新:似乎没有关于测试 - 编译目标的编织建议不是导致控制台测试失败的原因,而是弹簧配置的另一个问题。
答案 0 :(得分:2)
注册aspectj插件是不够的,你还需要注册一些目标:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<!-- use this goal to weave all your main classes -->
<goal>test-compile</goal>
<!-- use this goal to weave all your test classes -->
</goals>
</execution>
</executions>
</plugin>