Announcement Announcement Module
Collapse
No announcement yet.
AspectJ with LTW not weaving all classes when pointcut matches "too many" methods??? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AspectJ with LTW not weaving all classes when pointcut matches "too many" methods???

    I have a very large Spring @MVC application that I am trying to use Load Time Weaving for to implement trace logging (I am using it for something else, too, but that pointcut only applies to a few methods instead of all methods in the entire application). I prefer this over putting trace statements in every method, because in makes the code cleaner and makes every trace statement uniform throughout the application.

    I am using Spring 3.0.5 and AspectJ 1.6.9 (I am going to work on upgrading to 3.1 and 1.6.12 to see if that helps, but I wanted to go ahead and get this out there while I work on that, to see if anyone has any ideas).

    My development environment is Tomcat 6.0.32 running under Windows 7 Professional, with IntelliJ IDEA as my IDE.

    In my web application I have META-INF/context.xml:

    Code:
    <?xml version='1.0' encoding='utf-8'?>
    <Context antiJARLocking="true">
    	<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader" useSystemClassLoaderAsParent="false" />
    </Context>
    And I can see that the class loader is working (logged message: "[TomcatInstrumentableClassLoader@1e3cc77] info register classloader org.springframework.instrument.classloading.tomcat .TomcatInstrumentableClassLoader@1e3cc77")

    In my applicationContext.xml file, among other bean definitions, I have:

    Code:
    <context:load-time-weaver aspectj-weaving="on" />
    <context:component-scan base-package="com.example" />
    <context:annotation-config />
    I also have WEB-INF/classes/META-INF/aop.xml:

    Code:
    <!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
    <aspectj>
    	<weaver options="-verbose -showWeaveInfo">
    		<include within="com.example.aspect..*" />
    		<include within="com.example.health..*" />
    	</weaver>
    
    	<aspects>
    		<aspect name="com.example.aspect.TraceLoggingAspect" />
    		<aspect name="com.example.aspect.AnnotationParameterValidatorAspect" />
    	</aspects>
    </aspectj>
    Each aspect has one pointcut.

    I have a class, com.example.health.business.config.service.Registr ationServiceDefault, that I knew both pointcuts apply to and another class that I knew only the trace logging pointcut applies to, but AspectJ was not weaving either of them. I could see from the logged weaving info that it was weaving a bunch of other classes, but not those two classes.

    So, on a hunch, I changed
    Code:
    <include within="com.example.health..*" />
    to
    Code:
    <include within="com.example.health.business.config.service..*" />
    . When I did this, com.example.health.business.config.service.Registr ationServiceDefault suddenly got weaved (and advised by both pointcuts, just as expected. I could see it in the logged weaving info.

    I then changed
    Code:
    <include within="com.example.health.business.config.service..*" />
    to
    Code:
    <include within="com.example.health.business.config..*" />
    and it was still weaving the class, as per the logged weaving info.

    I then changed
    Code:
    <include within="com.example.health.business.config..*" />
    to
    Code:
    <include within="com.example.health.business..*" />
    and it was still weaving the class, as per the logged weaving info.

    I then changed
    Code:
    <include within="com.example.health.business...*" />
    back to
    Code:
    <include within="com.example.health..*" />
    and suddenly it stopped weaving that class again.

    So I tried the same thing with the other class (in a different package) that I knew should only be advised by one of the pointcuts, and as long as my include wasn't too broad, it would weave it, but as soon as I made it broader to a point, it stopped weaving it.

    But I have literally hundreds of other classes that ARE getting weaved appropriately, no matter how broad I make it.

    It's almost like I have "too many" methods that the pointcuts apply to. I thought that maybe it was trying to weave classes in a separate thread from Spring starting, so that maybe it was loading the missing classes BEFORE the weaver got around to them. But as long as the classloader has initialized, classes should always get weaved BEFORE the classloader ever returns them, right?

    Any ideas what's going on??? *scratches head*
Working...
X