以下是我执行此步骤的步骤。这给了我编译时的编织。如果您需要其他策略,显然您需要其他方法(例如用于运行时AOP代理的Spring
AOP)。
- 添加一个属性以标准化您使用的AspectJ版本:
<properties> <aspectj.version>1.7.2</aspectj.version> ...
- 添加运行时依赖项:
<dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>${aspectj.version}</version> </dependency>- 添加AspectJ Maven插件:
<plugin> <groupId>org.prehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.4</version> <executions> <execution> <goals> <goal>compile</goal> <goal>test-compile</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>${aspectj.version}</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjtools</artifactId> <version>${aspectj.version}</version> </dependency> </dependencies> <configuration> <source>1.7</source> <target>1.7</target> <forceAjcCompile>true</forceAjcCompile> </configuration> </plugin>我不确定这是否
forceAjcCompile真的有意义,但我发现有些情况下各个方面的应用不一致。我现在(现在)将其归咎于Eclipse覆盖类文件之类的东西,因此将
forceAjcCompile。
我做的其他事情:
- 添加
src/main/aspects
为额外的源目录(build-helper-maven-plugin
插件)。只是因为它在Eclipse中看起来不错 - 为AspectJ插件(插件)添加一个
pluginExecution
/ 并将其设置为和,以便在Eclipse中进行编码和测试(使用m2e)时也要(重新)应用各方面。pluginExecutionFilter
lifecycle-mapping
execute``runOnIncremental



