Reputation: 4291
I created aspectJ
class in seperate Maven project:
@Aspect
public class AspectE {
@Pointcut("execution(@EntryPoint * *.*(..))")
public void defineEntryPoint() {
}
@Before("defineEntryPoint()")
public void setThreadName(JoinPoint joinPoint) {
...
}
@After("defineEntryPoint()")
public void removeThreadName(JoinPoint joinPoint) {
...
}
}
Then in second project I annotated several methods and added to pom.xml
:
<dependency>
<groupId>first-project</groupId>
<artifactId>first-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.0</version>
</dependency>
But still aspects aren't seen at all. Am I missing some steps? What should I do?
Upvotes: 1
Views: 2005
Reputation:
I had the same problem ... but after I added this maven repo it's working
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.9</version>
</dependency>
Upvotes: 0
Reputation: 723
In order to weave correctly your code with your libraries, you should declare them within your dependencies AND within the aspectj weaver:
<dependencies>
<!-- Aspectj lib -->
<dependency>
<groupId>com.my.group</groupId>
<artifactId>my-aspect-lib</artifactId>
<version>1.0</version>
</dependency>
<!-- Other dependencies -->
</dependencies>
<build>
<!-- Specific build configuration -->
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<configuration>
<aspectLibraries>
<aspectLibrary>
<groupId>com.my.group</groupId>
<artifactId>my-aspect-lib</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
</plugin>
<!-- Other plugins configuration -->
</plugins>
</build>
<!-- Other settings -->
Upvotes: 2
Reputation: 11705
You have to weave the aspects with the code. This can be done in 2 ways:
Load-time weaving is a bit more versatile, but can be a bit challenging to set up properly. It consumes more CPU during startup (when the weaving happens), and also has a memory footprint. Compile-time weaving consumes more CPU during the compilation, obviously, but then you don't pay the price on each restart.
Upvotes: 1
Reputation: 8606
Did you take a look at this?
AspectJ compiler Maven Plugin - Usage
Upvotes: 3