2012-05-09 5 views
3

私はAspectJを既存のプロジェクト(実際には、それは重要ではないと思われたので、あまり知らない)に入れようとします。AspectJとMaven

@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のに新たなんだので

AJC を使用しないように織りロード時間を使用することにしましたそれはうまくいっている、すべてがいいです。

次のステップとして、AspectJとMavenを併用しようとしました。私はちょうどロギングの側面をちょっと変えました(ただのパッケージ)。

は、「アクションでAspectJの」ブックからのコードによると、私たちのMavenのpom.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クリーンを呼び出そうと、私はエラーの数千人を取得し、最初のものはあるインストールします。

[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事前に

をいただき、ありがとうございます。

答えて

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

Privet Eugene実際、私はこれらの詳細を追加するのを忘れてしまった。しかし、aspectjrtとaspectjweaverはpomにあります。xml – Tima

+0

振る舞いに影響を与えるコンフィギュレーションのソースとターゲットのバージョン – Tima

+0

ポイントカット宣言はde.test.beans.IPersonクラスを参照しており、コンパイル警告はcom.bmw.psdz.api.Serviceです。したがって、あなたが間違った例を提供したか、エラーがあなたが示したコードに関連していません。 –

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(); 
    } 
} 

iは、名前のパターンに誤りがありhere in detail

+0

助けて!ありがとう! –

0

検索この

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

使用しています。 任意のタイプのアスタリスクをお試しください:

@Pointcut("call(public * de.test.beans.IPerson+.*(..))") 
関連する問題