我在编译时使用 Spring aop 和 Aspectj。项目结构如下
parent-module
|---aop
|---service
|---web-app
与aop相关的东西,包括注解接口和方面在项目aop中,aop注解在项目服务中使用,服务在web-app中使用
aspectj 编译时编织适用于 service 和 web-app,pom 就像
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.8</version>
<configuration>
<weaveDependencies>
<weaveDependency>
<groupId>com.group</groupId>
<artifactId>aop</artifactId>
</weaveDependency>
</weaveDependencies>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
<complianceLevel>1.8</complianceLevel>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<showWeaveInfo>true</showWeaveInfo>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
这样,它完美地工作。
但既然我认为方面在编译时被编织到服务中,为什么我不能从 web-app 中删除 aspectj 编译器,那么
java.lang.NoSuchMethodError: aspectOf() 错误
在调用方面时发生。
为什么会这样?我可以在 web-app 的 pom 中放入什么来使服务的方面工作?我是否必须让 aspectj 在编译时同时编织服务和网络应用程序?