Skip to main content

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

Hmm!

Tanks.

" but have no idea that it exists an aspect"?

Maybe a solution: Spring solve this probelm with a very simply way.
Get the selected package (maybe in aspectj possible using <include>
for this) and get all file-s and directories with
classloader.getResource method. And if the selected class is an
@Aspect... load it...


Janos


-----Original Message-----
From: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Simone Gianni
Sent: Thursday, October 02, 2008 3:17 PM
To: aspectj-users@xxxxxxxxxxx
Subject: 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/

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top