AspectJ :: Surefire 测试给出 NoSuchMethodError

发布于 2024-10-22 07:38:25 字数 2765 浏览 4 评论 0原文

我正在对现有类进行编译时 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 中的 Surefire 插件配置,

        <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有任何帮助!

谢谢 !! 吉里什

I'm doing the compile time AspectJ weaving on existing classes, that is working beautifully in eclipse(AJDT). But when I run test in in maven using surefire , the test cases of this class where the aspects are applied are failing. I'm quite sure the weaving is happening correctly, it looks like a class path issue. Following is the error when I execute the surefire test.

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

Following is my surefire plugin config in 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>

I tried various things but it didn't work, any suggestions will be greately appreciated !!

Is there any need to have a aop.xml for this to work ?
Following is the aspectj plugin info.

<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>

As I need compile time weaving only, I have no aop.xml configured.

Any help on tjis please !

Thanks !!
Girish

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁许谁一生繁华 2024-10-29 07:38:25

三个建议:

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

Three suggestions:

  1. Make sure that your aspectj plugin for maven is configured correctly. If you have any questions about that, paste that part of your pom.xml in your question above.
  2. Make sure that your aop.xml references all of the required aspects.
  3. Make sure that your aspect-path/in-path is configured properly.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文