2011-11-02 281 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。