2011-11-02 63 views
2

我想在我們的項目中使用aspectj maven插件,它有多個模塊。按照此鏈接給出的說明http://mojo.codehaus.org/aspectj-maven-plugin/weaveJars.htmlAspectJ Maven插件<weaveDependency>

我正在使用@Aspectj註釋。我的方面是所謂的

的artifactId一個單獨的Maven模塊 - 消費者

,我想攔截還是建議是,其方法的類中

的artifactId - 製片

我在消費者模塊的pom文件中添加了以下配置:

 <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>aspectj-maven-plugin</artifactId> 
      <version>1.4</version> 
      <configuration>     
       <source>1.6</source> 
       <target>1.6</target> 
       <showWeaveInfo>true</showWeaveInfo> 
       <weaveDependencies> 
        <weaveDependency> 
         <groupId>com.home.demo</groupId> 
         <artifactId>producer</artifactId> 
        </weaveDependency> 
       </weaveDependencies> 
      </configuration> 
      <executions> 
       <execution> 
        <goals> 
         <goal>compile</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

在同一個pom文件中還添加了「producer」作爲依賴項。

當我正在爲消費者模塊進行mvn clean install時,控制檯中會出現以下信息。

[INFO] [AspectJ的:編譯{執行:默認}] [INFO]加入點「的方法執行中(空隙com.home.demo.producer.messaging.MomServiceEndpointListener.handle(com.home.messaging .service.MessageContext,com.home.messaging.service.MessageContext))'在 中輸入'com.home.demo.producer.messaging.MomServiceEndpointListener'(MomServiceEndpointListener.java:21)。 demo.ods.app.OdsConsumer'(OdsConsumer.java:38)

但是在執行應用程序時,它不起作用。該方面沒有被調用。 我無法理解我是否缺少一些東西。

此外,我很困惑,上面顯示的插件配置應該在哪個模塊使用者(我的方面是哪裏)或生產者。

回答

2

問題是weaveDependencies只能像來源一樣。

您的消費者模塊從weaveDependencies(producer)獲取原始「源」,將它們與方面編織並將編織類放入消費者(!!!)目標/類中。

因此,製作人工件永遠不會知道有關方面,並且您不會改變它。

您必須使用consumer/target/classes中的類重新構建生產者jar。 我不認爲這很方便,所以我離開了我的嘗試,以這種方式使用這個插件。 此外,幾個weaveDependencies將被合併到一個類的廢料堆中。

你最好從內置於生產者的外部jar依賴項和插件配置中嘗試Aspects。