3

私はAspectJを既存のプロジェクトで動作させようとしています(実際、そのプロジェクトは重要ではないと思われたため、あまり知りません)。

ajcを使用しないように、ロードタイムウィービングを使用することにしました。

私はAspectJを初めて使用するため、最初にいくつかのクラスとロギングアスペクトを備えたサンプルプロジェクトを作成しました。

@Aspect
public class LoggingAspect {

    @Pointcut("call(public de.test.beans.IPerson+.*(..))")
    public void logExecutions(JoinPoint jp) {}

    @Before("logExecutions(jp)")
    public void beforeExecutions(JoinPoint jp) {
        BeforeExecutionLog log = new BeforeExecutionLog(jp);
        System.out.println(log);                
    }

    @AfterReturning(pointcut = "logExecutions(jp)", returning = "ret")
    public void afterExecutions(JoinPoint jp, Object ret) {
        AfterExecutionLog log = new AfterExecutionLog(jp, ret);        
        System.out.println(log);        
    }    

}

それはうまく機能しています、すべてがいいです。

次のステップとして、AspectJとMavenを一緒に使用しようとしました。ロギングの側面を少し変更しました(パッケージのみ)。

「AspectJinAction」という本のコードによると、mavenpom.xmlを変更しました

       <dependencies>
            ...
        <dependency>
           <groupId>org.aspectj</groupId>
           <artifactId>aspectjrt</artifactId>
           <version>1.6</version>
        </dependency>

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.6.12.M1</version>
        </dependency>       
       </dependencies>
        <plugin>                                                 
            <groupId>org.codehaus.mojo</groupId>            
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.4</version>
            <executions>                                         
                <execution>                                      
                    <goals>                                      
                        <goal>compile</goal>                     
                    </goals>                                     
                    <configuration>                              
                        <source>1.5</source>                     
                        <target>1.5</target>                     
                    </configuration>                             
                </execution>                                     
            </executions>                                        
        </plugin>   

しかし、 mvn clean installを呼び出そうとすると、何千ものエラーが発生し、最初のエラーは次のようになります。

[ERROR] Syntax error on token "call(public xxx.yyy.zzz.api.Service+.*(..))", "name pattern" expected
[ERROR] Method annotated with @Pointcut() for abstract pointcut must be abstract

次のエラーもあります。

[ERROR] The method xyz() of type zyx must override a superclass method

これらはすべて私の側面の影響を受ける方法だと思います。

誰かが私を説明できますか、何が問題なのですか?

前もって感謝します

UPD:

質問を更新しました。

4

3 に答える 3

2

あなたの例は不完全に見え、あなたが示したエラーはコードと一致しませんが、次のpom.xmlを使用してアスペクトクラスをコンパイルする際の問題は見られません。

<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.test</groupId>
    <artifactId>test2</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.6.11</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <source>1.5</source>
                            <target>1.5</target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
于 2012-05-09T17:35:31.753 に答える
2

多分それは誰かのために役立つでしょう。

[ERROR] The method xyz() of type zyx must override a superclass method

このエラーが表示されたら、javac ver1.5を使用してコードをコンパイルし、javaクラスに実装されたばかりのメソッドに@Overrideアノテーションを付けようとします。

public interface A { void someMethod(); }
public class B implements A {
  @Override
  public void someMethod() {
    doSomething();
  }
}

私はこれを使います

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
  </configuration>
</plugin>

詳細はこちらをご覧ください

于 2013-02-01T07:38:07.710 に答える
0

名前パターンにエラーがあります:戻りタイプがありません。すべてのタイプでアステリックスを試してください。

@Pointcut("call(public * de.test.beans.IPerson+.*(..))")
于 2015-07-20T12:33:48.287 に答える