Announcement Announcement Module
No announcement yet.
Converting from Spring AOP to AspectJ LTW Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Converting from Spring AOP to AspectJ LTW

    I have an @AspectJ-style aspect that I have been using for logging in a Tomcat web application, using Spring AOP autoproxying to good effect. I have now run into a situation where I need to profile code whose source code I cannot control, and which is currently unsuitable (for a variety of reasons) to be managed by Spring.

    After reading the documentation, it sounded like enabling full AspectJ LTW would be the answer to my problems. Unfortunately, this has proven to be an exercise in frustration thus far. As I know that I already have a working aspect with valid pointcuts, I am first attempting to migrate it from Spring AOP to AspectJ LTW before trying to add new pointcuts to non-Spring managed code. Thus far, my attempts have ended in abject failure.

    Steps taken:
    • Add org.springframework.instrument.tomcat-3.0.2.RELEASE.jar to $CATALINA_HOME/lib.
    • Add
      <context:load-time-weaver />
      to my main web application context.
    • Create a META-INF/aop.xml that contains the following (taken from Spring documentation):
      <?xml version="1.0" encoding="UTF-8"?>
      		<!-- weave in just this aspect -->
      		<aspect name="com.mycompany.logging.LoggingAspect" />
      	<weaver options="-debug -Xset:weaveJavaxPackages=true">
      		<!-- only weave classes in our application-specific packages -->
      		<include within="com.mycompany..*" />
    • Added the following line to context.xml:
      <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"
          	useSystemClassLoaderAsParent="false" />

    The only evidence I have that the class loader is being picked up is the following message from Tomcat when it loads the web application context:
    [[email protected]] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified
    In order to try and debug this, I added -Xset:weaveJavaxPackages=true to my aop.xml, but I still receive the warning. My (perhaps erroneous?) assumption based on this is that my aop.xml is not being read. I have examined the expanded WAR directory within $CATALINA_HOME/webapps, and have found the aop.xml exactly where it should be, in META-INF. This is tough to debug because I have been unable to figure out how to get the tools involved to give me debugging output with which to move forward. Any suggestions or hints people have on how I can get more information out of this setup would be very much appreciated.


  • #2
    Originally posted by wrbriggs View Post
    …-Xset:weaveJavaxPackages=true to my aop.xml, …
    I would say that -Xset:weaveJavaxPackages=true looks like a JVM parameter…
    and specifying a JVM parameter in a XML file that would be read after the code was loaded by the JVM, has no way to affect how the JVM loads the code…


    • #3
      Just a quick update: By setting -Dorg.aspectj.tracing.enabled=true and -Daj.weaving.verbose=true -Dorg.aspectj.weaver.showWeaveInfo=true in my JAVA_OPTS environment variable, I've received the following output. I believe that it shows my classloader configuration is proper, and that the Spring-specific AspectJ aspects are being loaded, while my aop.xml in my webapp META-INF/ directory is still being ignored. Does anyone have any further thoughts on this? Would it be more appropriate to bring my question to an AspectJ-specific forum or mailing list since I can show the Spring aspects being loaded?

      [[email protected]] info AspectJ Weaver Version 1.6.9 built on Monday Jul 5, 2010 at 15:28:35 GMT
      [[email protected]] info register classloader org.springframework.instrument.classloading.tomcat [email protected]
      [[email protected]] info using configuration file:/usr/local/apache-tomcat-6.0.26/webapps/analytics/WEB-INF/lib/spring-aspects-3.0.2.RELEASE.jar!/META-INF/aop.xml
      [[email protected]] info register aspect org.springframework.beans.factory.aspectj.Annotati onBeanConfigurerAspect
      [[email protected]] info register aspect org.springframework.transaction.aspectj.Annotation TransactionAspect


      • #4
        I have the same issue

        [[email protected]] info using configuration file:/E:/dev/MAVEN_REPO/org/springframework/spring-aspects/3.0.5.RELEASE/spring-aspects-3.0.5.RELEASE.jar!/META-INF/aop.xml
        in both our case it seems the aop.xml from the spring-aspects jar is took in place of the defined one
        Last edited by etrier; Mar 28th, 2011, 10:47 AM.


        • #5
          I found a solution from here

          the META-INF must be in a resource folder like src/main/resources/META-INF/aop.xml


          • #6
            Originally posted by etrier View Post
            I found a solution from here

            the META-INF must be in a resource folder like src/main/resources/META-INF/aop.xml
            Thanks!. This was very helpful. I was sure that the aop.xml file had been ignored but I did not how to fix it. Now it works!