【问题标题】:AspectJ :: Surefire tests gives NoSuchMethodErrorAspectJ :: Surefire 测试给出 NoSuchMethodError
【发布时间】:2011-03-18 00:14:55
【问题描述】:

我正在对现有类进行编译时 AspectJ 编织,这在 eclipse(AJDT) 中运行良好。但是当我使用 surefire 在 maven 中运行测试时,应用了方面的此类的测试用例失败了。我很确定编织是正确的,它看起来像一个类路径问题。以下是我执行surefire测试时的错误。

java.lang.NoSuchMethodError: com.online.station.OBSDescriptorBrokerageMortgageRemovalAspect.aspectOf()Lcom/online/station/OBSDescriptorBrokerageMortgageRemovalAspect; 在 com.online.station.delegate.fundstransfer.AuthorizeAccForTransfDelegImpl.unpackResponse(AuthorizeAccForTransfDelegImpl.java:111)

以下是我在 pom.xml 中的肯定插件配置

        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <forkMode>once</forkMode>
                <argLine>
                    -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                </argLine>
                <useSystemClassloader>true</useSystemClassloader>
                <includes>
                    <include>**/*Test.java</include>
                </includes>
                <excludes>
                    <exclude>**/WebTestCase.java</exclude>
                </excludes>
            </configuration>
        </plugin>

我尝试了各种方法,但没有成功,任何建议将不胜感激!

是否需要有一个 aop.xml 才能工作? 以下是aspectj插件信息。

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
    <verbose>true</verbose>
    <complianceLevel>${jdk.source.version}</complianceLevel>
    <target>${jdk.target.version}</target>
    <showWeaveInfo>true</showWeaveInfo>
    <weaveMainSourceFolder>true</weaveMainSourceFolder>
    <includes>
        <!-- Class AspectClass1 and dependencies -->
        <include>**/AspectClass1*</include>
        <include>**/Class2*</include>
        <include>**/Class3*</include>
        <include>**/Class4*</include>
        <include>**/Class5*</include>
        <include>**/Class6*</include>
        <include>**/Class7*</include>
        <include>**/Class8*</include>

    </includes>
</configuration>
<executions>
    <execution>
    <goals>
        <goal>compile</goal>                <goal>test-compile</goal>       </goals>
    </execution>
   </executions>

由于我只需要编译时编织,我没有配置 aop.xml。

请对 tjis 有任何帮助!

谢谢!! 吉里什

【问题讨论】:

    标签: aspectj surefire


    【解决方案1】:

    三个建议:

    1. 确保您的 maven 的 aspectj 插件配置正确。如果您对此有任何疑问,请将 pom.xml 的该部分粘贴到上面的问题中。
    2. 确保您的 aop.xml 引用了所有必需的方面。
    3. 确保您的 aspect-path/in-path 配置正确。

    【讨论】:

    • 嘿安德鲁...再次感谢。我在问题中添加了 aspectj 插件详细信息。我有点困惑,我正在做编译时编织(不是加载时间)然后我还需要 aop.xml 吗?有什么方法可以在 pom 的 inpath 上提供 aspectpath 吗?
    • Girish,你有没有得到这个答案?我也想知道是否需要aop.xml文件。
    • 第一次肯定错过了这个问题。不,编译时编织不需要 aop.xml。
    猜你喜欢
    • 2013-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-17
    相关资源
    最近更新 更多