[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] AspectJ runtime weaving aspects not declared in aop.xml

I agree that the error message from Spring about the treatment of aspects compiled with 'ajc' could be improved. If you can file a JIRA issue (for Spring), that will be great.

As for LTW picking up @Aspect aspects, it shouldn't really happen; only aspects that are declared in aop,xml (and variations of it such as aop-ajc.xml) are woven in as long as no exclude statements exclude it. So something else is going on here. Do you have another aop.xml (or aop-ajc.xml created by 'ajc -outxml' option). What happens when you explicitly exclude the aspect?


On Wed, Jul 29, 2009 at 7:41 PM, Satish Terala <satish.terala@xxxxxxx> wrote:
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 'ajc$'.

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);

Then I get the exception
org.springframework.aop.framework.AopConfigExcepti on: Advice must be
declared inside an aspect type: Offending method 'public void
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
<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..*"/> -->
<!-- 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.ApplyDispatchLevelsAdvice"/>
<aspect name="ca.xxxx.yy.services.advices.DDSAvailableOffsetAdvice"/>
<aspect name="ca.xxxx.yy.services.advices.EnergyMarketAuto
<aspect name="ca.xxxx.yy.services.advices.FilterLongLeadAssetAdvice"/>
<aspect name="ca.xxxx.yy.services.pointcuts.OffsetAspectsPrecedence"/>

and My aspect is declared in a file

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

public class DtExceptionHandlerAdvice {

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.

Any reason why this might be happening, Does AspectJ LTW simply pick up
all classes with @Aspect and consider them as aspects, if that is the
case should I now have to exclude the ones that I don't want to be woven

Any help would be appreciated.

aspectj-users mailing list