Announcement Announcement Module
No announcement yet.
AspectJ LTW and Spring AOP not working together Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • AspectJ LTW and Spring AOP not working together

    I want to use both AspectJ LTW and Sprint AOP in tmy web application. I want to use AspectJ LTW to inject advice to non-spring managed classes and use Spring AOP for spring-managed classes. When I tried to do that, Spring AOP no longer injects the advices which does prior to using LTW.

    Here are my aop.xml and applicationContext.xml:

         options="-verbose -showWeaveInfo -XmessageHandlerClass:org.springframework.aop.aspectj.AspectJWeaverMessageHandler">
         <include within="com.atc.ideal.vehicle.*"/>
         <exclude within="com.atc.ideal.service.audit.AuditableAspect"/>
         <aspect name="com.atc.ideal.service.audit.AuditableAspect"/>
         <include within="com.atc.ideal.service.audit.AuditableAspect"/>
        <bean name="autoproxyAspect" class="com.atc.ideal.service.audit.AuditableAspect">
    After doing some research on my own, it appears to me that the AspectJ LTW weaves the AuditableAspect class (even it was excluded in the aop.xml file). When it does, it adds two fields begin with 'ajc$'. When Spring tries to apply the advice in AuditableAspect defined as 'autoproxyAspect' bean, it refuses to apply it because it was woven by LTW, as determined by the presence of the two fields with 'ajc$' prefix.

    Based on this finding, it seems to me that there is no way to mix LTW and Spring AOP in the same application, unless I missed something. Can someone clarify this?

    I am using Spring 2.0.6 and AspectJ 1.5.3. I tried using the 1.6.3 aspectjweaver.jar but that didn't make a difference. I am not in the position to upgrade to Spring 2.5.x.

  • #2
    Sorry, here is the aspect:

    public class AuditableAspect {
        @Around(value="execution(* com.atc.ideal.vehicle..set*(Object)) && @annotation(com.atc.ideal.audit.Auditable)", argNames="jp")
        public void auditableData(ProceedingJoinPoint jp) throws Throwable {...}