aspectj

Spring, Aspects, @Configurable and Compile Time Weaving using maven

Why do most people use Load Time Weaving (LTW)? It requires replacing the javaagent/classloader of your JVM which can lead to all sorts of issues.

Let's take a look at getting Compile Time Weaving (CTW) instead.

This post is using spring 2.5.2, aspectj 1.5.4, java 1.5. (Spring 2.5.4 uses a later version of weaver (3.0 vs. 5.0) - I assume AspectJ 1.6.0 but the aspectj-maven-plugin is also based around 1.5.4 - so for now we'll stick with this combination.)


Compile Time Weaving of spring aspects in Intellij Idea

To enable compile time weaving of the spring aspects (spring-aspects.jar) in Intellij IDEA (I am using 7.0.3 - but I assume this to be similar for other versions):

  1. Install and enable the AspectJ plugin (http://intellij.expertsystems.se/aspectj.html) - it was available in the plugin manager lists by default
  2. Under Settings > AspectJ Weaver, search for aspects - add the spring-aspects jar and enable weaving
  3. In the build menu - make sure AspectJ weaving is enabled

Illegal type in constant pool

After adding

CATALINA_OPTS=-javaagent:/path/to/aspectweaver-1.5.3.jar

tomcat started failing - giving an "Illegal type in constant pool" about log4j.

This seems mainly to be due to lib differences.

To get this running on tomcat 5.5.23 I had to:

1) copy the log4j jar from my webapp to the common/lib dir (log4j was not present here before)

2) copy the commons-logging-api jar to the bin directory (replacing the version that was here before).

It seems that aspectjweaving can cause increased sensitivity to classloading/versioning problems.

Spring AOP and maven dependencies (<aop:spring-configured/>)

Or - why does it say my spring context xml is invalid on <aop:spring-configured/>

I've been trying to add the @Configurable to a spring project.

This means that I had to have a <beans> tag that looks like

Subscribe to RSS - aspectj