Reputation: 12905
I try to get AspectJ working in an exisiting project (actually I don't know much about that project, because it seemed unimportant).
We decided to use the load time weaving to avoid using ajc
Because I'm new to AspectJ I created first an example project with some classes and a logging aspect:
@Aspect
public class LoggingAspect {
@Pointcut("call(public de.test.beans.IPerson+.*(..))")
public void logExecutions(JoinPoint jp) {}
@Before("logExecutions(jp)")
public void beforeExecutions(JoinPoint jp) {
BeforeExecutionLog log = new BeforeExecutionLog(jp);
System.out.println(log);
}
@AfterReturning(pointcut = "logExecutions(jp)", returning = "ret")
public void afterExecutions(JoinPoint jp, Object ret) {
AfterExecutionLog log = new AfterExecutionLog(jp, ret);
System.out.println(log);
}
}
It's working fine, everything is nice.
As next step I tried to use AspectJ and Maven together. I just changed the logging aspect a bit (just the package).
According to code from the book "AspectJ in Action" I modified our maven pom.xml
<dependencies>
...
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.12.M1</version>
</dependency>
</dependencies>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</execution>
</executions>
</plugin>
But if try to call mvn clean install I get thousands of errors and the first one is:
[ERROR] Syntax error on token "call(public xxx.yyy.zzz.api.Service+.*(..))", "name pattern" expected
[ERROR] Method annotated with @Pointcut() for abstract pointcut must be abstract
There are also following errors:
[ERROR] The method xyz() of type zyx must override a superclass method
I guess these are all methods which are affected by my aspect.
Can anybody explain me, what is wrong?
Thank you in advance
UPD:
I updated my question.
Upvotes: 3
Views: 7209
Reputation: 1338
There is an error in a name pattern: return type is missing. Try asterix for any type:
@Pointcut("call(public * de.test.beans.IPerson+.*(..))")
Upvotes: 0
Reputation: 21
Maybe it will be useful for someone.
[ERROR] The method xyz() of type zyx must override a superclass method
this error appears then you try to compile code with javac ver1.5 and have @Override annotation over the methods that just implemented in java class.
public interface A { void someMethod(); }
public class B implements A {
@Override
public void someMethod() {
doSomething();
}
}
i use this
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
Find here in detail
Upvotes: 2
Reputation: 31795
Your example seem incomplete and errors you showed doesn't match the code, but I don't see any issues compiling your aspect class using the following pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.test</groupId>
<artifactId>test2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.11</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Upvotes: 2