Results 1 to 6 of 6

Thread: Converting from Spring AOP to AspectJ LTW

  1. #1
    Join Date
    May 2010
    Posts
    22

    Default 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
      Code:
      <context:load-time-weaver />
      to my main web application context.
    • Create a META-INF/aop.xml that contains the following (taken from Spring documentation):
      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <aspectj>
      	<aspects>
      		<!-- weave in just this aspect -->
      		<aspect name="com.mycompany.logging.LoggingAspect" />
      	</aspects>
      	<weaver options="-debug -Xset:weaveJavaxPackages=true">
      		<!-- only weave classes in our application-specific packages -->
      		<include within="com.mycompany..*" />
      	</weaver>
      </aspectj>
    • Added the following line to context.xml:
      Code:
      <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:
    [TomcatInstrumentableClassLoader@2c979e8b] 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.

    Regards,
    Will

  2. #2
    Join Date
    Dec 2007
    Posts
    27

    Default

    Quote 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. #3
    Join Date
    May 2010
    Posts
    22

    Default

    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?

    [TomcatInstrumentableClassLoader@37722456] info AspectJ Weaver Version 1.6.9 built on Monday Jul 5, 2010 at 15:28:35 GMT
    [TomcatInstrumentableClassLoader@37722456] info register classloader org.springframework.instrument.classloading.tomcat .TomcatInstrumentableClassLoader@37722456
    [TomcatInstrumentableClassLoader@37722456] 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
    [TomcatInstrumentableClassLoader@37722456] info register aspect org.springframework.beans.factory.aspectj.Annotati onBeanConfigurerAspect
    [TomcatInstrumentableClassLoader@37722456] info register aspect org.springframework.transaction.aspectj.Annotation TransactionAspect
    Thanks,
    Will

  4. #4
    Join Date
    Sep 2010
    Posts
    25

    Default

    I have the same issue

    [WebappClassLoader@df0256] 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 at 09:47 AM.

  5. #5
    Join Date
    Sep 2010
    Posts
    25

    Default

    I found a solution from here http://blogexpertease.alti.com/index...vec-spring-aop

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

  6. #6
    Join Date
    Jun 2009
    Posts
    1

    Default

    Quote Originally Posted by etrier View Post
    I found a solution from here http://blogexpertease.alti.com/index...vec-spring-aop

    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •