So the other answer is also valid, but I thought I would talk a little more about some of the implications of this approach.
The setup I'm using is at a basic level: -
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.4</version> <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> <outxmlfile>META-INF/aop.xml</outxmlfile> <aspectLibraries> <aspectLibrary> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> </aspectLibrary> </aspectLibraries> <source>1.7</source> <target>1.7</target> <forceAjcCompile>true</forceAjcCompile> </configuration> </plugin>
Now, more information about dependencies: -
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${dep.spring}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>${dep.spring}</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>${aspectj.version}</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>${aspectj.version}</version> </dependency> <dependency> <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> <version>1.0</version> <scope>provided</scope> </dependency>
I assume that you will miss the persistence api, which is used for weaving.
Edit: associated with https://jira.springsource.org/browse/SPR-6819 error in spring. It looks like you need the persistence API for this.
It is also useful to create a maven task to weave if classes are not decoupled in ide (this is very common for me).
aspectj:compile
Finally, if you intend to unit test your classes, it may be useful to weave classes after this phase. We intertwine in the prepare-package phase. If you want to do this, add
<executions> <execution> <phase>prepare-package</phase> <goals> <goal>compile</goal> </goals> </execution> </executions>
In your plugin.
I hope this helps, because it can be difficult to make this approach play well in the IDE.
source share