I have a project where I want to use aspects but not use spring. So I'm using AspectJ. In my particular scenario, LTW won't work for me, so I have to use CTW, which leads me to the maven aspectj plugin. I am currently using Java 7. I am weaving an aspect written in one maven module into another module that has it as a dependency.
The plugin seems to weave correctly when I am weaving a non-annotated aspect, but when I switch it to an annotation based aspect, it seems like the plug in isn't writing in the hasaspect() and aspectof() methods because at runtime I get exceptions saying that the methods are not there.
One thing I tried was to have the annotation based aspect extend the Aspects class, in hopes that then it will be able to find the methods, but that also did not work.
my plug in is configured as such:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<showWeaveInfo>false</showWeaveInfo>
<Xlint>ignore</Xlint>
<source>1.7</source>
<target>1.7</target>
<complianceLevel>1.7</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>false</verbose>
<weaveDirectories>
<weaveDirectory>${project.build.outputDirectory}</weaveDirectory>
</weaveDirectories>
<aspectLibraries>
<aspectLibrary>
<groupId>my.group</groupId>
<artifactId>dependencywithaspecttoweave</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.7.2</version>
</dependency>
</dependencies>
My annotated aspect looks like this:
public class TraceLog extends Aspects {
private ComponentLogger logger;
@Pointcut(value = "within(my.package..*) && "
+ "execution(* *(..))")
public void scope() {
}
/**
* Before method.
*
* @param thisJoinPoint The joinpoint.
* @throws IllegalAccessException When it tries to get the logger and can't.
*/
@Before(value = "scope()")
public void logBefore(final JoinPoint thisJoinPoint) throws IllegalAccessException {
logMethod(thisJoinPoint, "Entering " + createLogMessage(thisJoinPoint));
}
...
What I've had to do is revert back to the plain old non-annotated aspect style. But this is a drag since I can't then throw exceptions from the method (or at least as of yet, I do not know how to). Throwing exceptions would be particularly useful for things like security, where if a user did not have access, an exception would be the appropriate way to alert the caller.
Thanks in advance.