I assume you already implemented your aspects. The next step that you have to do is to setup your pom.xml
properly
Aspect weaving in non-Spring projects
Usually this is nothing but adding one dependency org.aspectj:aspectjrt
and one build plugin org.codehaus.mojo:aspectj-maven-plugin
<dependencies>
...
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11</version>
<configuration>
<complianceLevel>1.8</complianceLevel>
<source>1.8</source>
<target>1.8</target>
<verbose>true</verbose>
<Xlint>ignore</Xlint>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>aspectj-compile</id>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
Aspect weaving in Spring projects
First, include all your aspects into the Spring context by adding @Component
to all Aspect classes.
@Aspect
@Component
public class MyLogger {
...
}
Second, add required dependencies to your pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
...
</dependencies>
If your project has another parent project (it also should be a Spring project) then you may not need org.springframework.boot:spring-boot-starter-aop
- just check.
You may also find these posts interesting: