【发布时间】:2011-07-07 13:46:19
【问题描述】:
我所有的 junit 测试都在 eclipse 中通过,但是当从控制台运行时,它们似乎为 AJ 类 RiskLogAspect.aj 抛出 ClassNotFoundException 我可以验证在 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]
更新:似乎没有在测试编译目标上编织建议并不是导致控制台上测试失败的原因,而是 spring 配置的另一个问题。
【问题讨论】:
-
当你说顶级包时 - 你是指源包还是父 maven 模块。您能否发布整个 pom 或至少相关部分
-
您是否使用 Maven...在 Eclipse 中更新项目配置?
-
我已尝试更新项目配置。该包也是 com.myproject.somepackage.X 并且所有内容都位于 somepackage 下面,所以我删除了它。