【问题标题】:Aspect not being found during runtime运行时未找到方面
【发布时间】:2011-09-15 22:47:17
【问题描述】:

我正在尝试将 aspectj 添加到使用 java 6.0 的 maven 项目中。 使用 1.4 版本的 aspectj-maven-plugin 和 1.6.11 版本的 aspectj。

这些类在一个外部依赖 jar 中,这里是 pom:

 <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <configuration>
      <complianceLevel>1.6</complianceLevel>
      <source>1.6</source>
      <target>1.6</target>          
      <showWeaveInfo>true</showWeaveInfo>
      <weaveDependencies>
        <weaveDependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>gem</artifactId>
        </weaveDependency>
      </weaveDependencies>          
    </configuration>
    <executions>
      <execution>
        <!-- Needs to run before the regular javac compile phase -->
        <phase>process-sources</phase>
        <goals>
          <goal>compile</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

这些方面似乎在构建期间应用得很好: 这是一个示例:

[INFO] --- aspectj-maven-plugin:1.4:compile (default) @ test ---
[INFO] Extending interface set for type 'test.pkg1.pkg2.PaymentEnquiry' (PaymentE
 nquiry.java) to include 'test.pkg1.pkg2.aj.AdditionalPaymentEnquiryMethods'    
(PaymentEnquiryExtensions.aj)

但是在运行时,我收到以下错误: java.lang.NoSuchMethodError:
test.pkg1.pkg2.Payment.setDetails(Ljava/util/List;)V

任何关于为什么会发生这种情况的想法都会很有帮助。

【问题讨论】:

  • 修改后的类文件到哪里去了?您确定在运行代码时在类路径中包含那些而不是未增强的?

标签: java maven aspectj


【解决方案1】:

最明显的原因是没有带签名的方法

void setDetails(List)

关于 test.pkg1.pkg2.Payment。它看起来不太像 AspectJ 问题——更像是运行时类路径上的错误代码问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-21
    • 1970-01-01
    • 2021-08-04
    • 2013-10-22
    • 2014-06-13
    • 1970-01-01
    相关资源
    最近更新 更多