Search code examples
javaspringtomcataspectjproxy-classes

Best practice in specifying the correct spring-instrument agent jar


I am planning to use AspectJ's loadtime weaving feature for proxying in a Spring based web application. The three things (AFAIK) that are needed to get this working are:

  1. Set the proxying mode to "aspectj" (as opposed to "proxy")
  2. Add the spring-aspects and the aspectjweaver to the classpath
  3. Add the spring-instrument agent to the VM startup

My question was on the best practice on how to achieve #3. My causes of concern are:

  1. Since this is needed at application startup, I can't have it point to the spring-instrument jar in the WEB-INF/lib location of my webapp. I was thinking of having a static spring-instrument jar sitting in my CATALINA_HOME/lib that can be directly referred to.
  2. As the web application progresses, it might be the case that the spring version may be upgraded and we may forget to upgrade the version of the jar in CATALINA_HOME/lib.
  3. Many different applications may be using the same CATALINA_HOME and it is not always possible to have everyone upgrade the spring-instrument jar in lock-step fashion.

Since this problem seems to be like a generic one, I wanted to know from others how they address this concern.

Thanks!


Solution

  • Depending on the container you don't need the spring-instrumentation.jar. A single <context:load-time-weaver /> in your configuration is enough.

    You will need a recent version of Tomcat (version 8), Jetty, WebSphere, Weblogic or JBoss.