Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] LTW and annotations

If I understand how LTW works correctly, the problem is in class loading.

Consider the situation where you have a bean with a doSomething method,
and then have an advice that does something before that method.

You application starts, it will load the bean with a new Bean(). At this
point, the class loader loads the bean, but have no idea that it exists
an aspect, so will not weave the bean. This is because, you never call
(and have explicitly no way) to call "new MyAspect()".

In fact, if you had such a way of instantiating aspects, another
situation could arise and cause problems. Suppose you have also a
tracing aspect, that will intercept all calls to all methods. If this
tracing aspect gets loaded AFTER the bean has already been loaded, the
class loader is not able anymore to modify the bean, because it has
already been loaded.

(in reality, there are some ways to do class redefining in recent
classloaders, but that brings another lot of problems)

So, yes, you have to define your aspects in the aop.xml file. Since this
is tedious, the ajc compiler can perform this task for you. If you are
using AJDT in Eclipse, there is an option for generating aop.xml on the
fly under the AspectJ section of you settings. If you are compiling from
command line using ajc, the -outxml option will generate it for you (see
http://www.eclipse.org/aspectj/doc/released/devguide/ajc-ref.html ).
Also, the maven2 plugin for aspectj will generate the aop.xml file for you.

Hope this helps,
Simone



Háber János wrote:
> Hi!
>
> I have a question. I want to write an application. I using javaagent
> vm option to LTW. But in this case what needed in aop.xml (aop.xml
> required in this case if I not want to set any special weaving
> options?)
> If I only write:
> <aspectj>
>     <weaver options="-verbose -showWeaveInfo"/>
> </aspectj>
>
> I get: "no aspects registered. Disabling weaver for class loader..."
> WTF? I need to set the aspects both aop.xml and annotation in java
> file? Why?
> If Yes, why? The classloader can't detect the annotations?
>
>
> Janos Haber
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>   


-- 
Simone Gianni            CEO Semeru s.r.l.           Apache Committer
MALE human being programming a computer   http://www.simonegianni.it/



Back to the top