Announcement Announcement Module
Collapse
No announcement yet.
AspectJ runtime weaving aspects not declared in aop.xml Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AspectJ runtime weaving aspects not declared in aop.xml

    I am not sure if this should come under AspectJ issue or if it is a Spring AOP issue.

    I have an aop.xml that declares certain aspects that I would like to be woven by AspectJ LTW. I also have other aspects that I would like Spring to apply (i want regualr proxy based mechanism for these).

    Spring has a restriction that it will not apply any aspects that have been woven by AspectJ Compiler.It does these by checking for any fields that start with 'aj$'.

    After struggling to understand why my Aspect that was not declared in aop.xml was not getting applied, I tried to apply the aspect programatically using
    AspectJProxyFactory aspectJProxyFactory=new AspectJProxyFactory(bean);
    aspectJProxyFactory.addAspect(DtExceptionHandlerAd vice.class);

    Then I get the exception
    org.springframework.aop.framework.AopConfigExcepti on: Advice must be declared inside an aspect type: Offending method 'public void ca.xxxx.yy.remote.endpoint.impl.DtExceptionHandler Advice.runtimeError(java.lang.RuntimeException)' in class [ca.xxxx.yy.remote.endpoint.impl.DtExceptionHandler Advice]

    Once I dig thru I find that the exception message is misleading because the advice is declared in an aspect type. The issue really is that when Spring checks if an advice class that is being applied is really an aspect type it checks for @Aspect to be present, or if its an aspect type and also if it has any ajc$ variables in it. Ideally the error message should have said that aspect has been woven by AspectJ Compiler, but thats another issue anyways.

    But really my problem is that AspectJ is weaving an aspect thats not been declared in its aop.xml file.

    Here is my aop.xml file
    <aspectj>
    <weaver options="-debug -verbose -showWeaveInfo">
    <!-- only weave classes in our application-specific packages -->
    <include within="org.quartz..*"/>
    <include within="ca.xxxx.yy.services..*"/>
    <include within="ca.xxxx.yy.dao..*"/>
    <include within="ca.xxxx.yy.newdispatch..*"/>
    <include within="ca.xxxx.yy.domain.entity.energy..*"/>
    <!-- <include within="ca.xxxx.yy.event.reciever..*"/> -->
    </weaver>
    <aspects>
    <!-- weave in just this aspect including only the aspects that we want woven by AspectJ Runtime -->
    <aspect name="ca.xxxx.yy.eventqueue.impl.SystimeAspect"/>
    <aspect name="ca.xxxx.yy.services.advices.LimitAdvice"/>
    <aspect name="ca.xxxx.yy.services.advices.ApplyDispatchLev elsAdvice"/>
    <aspect name="ca.xxxx.yy.services.advices.DDSAvailableOffs etAdvice"/>
    <aspect name="ca.xxxx.yy.services.advices.EnergyMarketAuto ReductionOffsetAdvice"/>
    <aspect name="ca.xxxx.yy.services.advices.FilterLongLeadAs setAdvice"/>
    <aspect name="ca.xxxx.yy.services.pointcuts.OffsetAspectsP recedence"/>
    </aspects>

    and My aspect is declared in a file



    package ca.xxxx.yy.remote.endpoint.impl;

    @Aspect
    public class DtExceptionHandlerAdvice {

    @Log
    Logger logger;
    }

    In my debug log I see the line

    [AppClassLoader@130c19b] debug weaving 'ca.xxxx.yy.remote.endpoint.impl.DtExceptionHandle rAdvice'

    And when running thru my debugger i do see that the DtExceptionHandlerAdvice does have two variables starting with ajc$ proving that it has indeed been woven by AspectJ load time weaver.

    Has any one seen such behaviour, apart from resorting to explicit excludes from aop.xml (which i suspect might not work) is there any other way (apart from using xml based aspects) to fix this.

    I will crosspost on AspectJ forum to see if they have any answers , but any help would be appreciated.

  • #2
    Aspectj allows to weave aspect logic to the aspects themself, so, I assume that the behavior you observe is connected to the '<include within="ca.xxxx.yy.services..*"/>' switch at the <weaver> aop.xml section. I.e. aspectj may just pick up your DtExceptionHandlerAdvice class during class loading because of that.

    You can explicitly exclude you aspect from weaving by adding '<exclude within="(@Aspect *)"/>'

    Comment


    • #3
      Thanks Denis for responding.

      I did think of that, that is the reason my DtExceptionHandlerAdvice is in a package (ca.xxxx.yy.remote.endpoint.impl) that is out of the list mentioned in the weaver section.

      Also I read on Andy Clement's blog on LTW that the line 'debug weaving 'ca.xxxx.yy.remote.endpoint.impl.DtExceptionHandle rAdvice' does not mean that LTW is actually weaving it, it just lists that this class is being conisdered to be woven (dont know why its picked up at all). I do have showWeaveInfo enabled , but that does'nt show if these aspects are getting woven into any code at all,i.e the advice itself is woven but its not woven into the code that its pointcuts apply to.

      -Satish

      Comment


      • #4
        Your idea looks correct and it seems at least logical that aspects to work on are listed at <aspects> sections but... there is no perfect software, so, I'd give it a try with exclusion at <weaver> section.

        Comment

        Working...
        X