Discussion:
[aspectj-users] Using Aspects.aspectOf for Spring DI
Tevoi Andrea
2012-08-10 08:36:52 UTC
Permalink
Hi all,



I developed an Aspect library with @AspectJ syntax and I use it via CTW to weave an application. I know that because I used java compiler, aspectOf and hasAspect are not generated, so I tried to use Aspects utility class to instantiate Aspect classes in Spring.



Here is the Spring xml fragment:




<bean class="org.aspectj.lang.Aspects" id="outputMessageLogger" factory-method="aspectOf">

<constructor-arg type="java.lang.Class" value="logging.OutputMessageLoggerAspect "/>

...



During startup this exception is thrown:

Factory method [public static java.lang.Object org.aspectj.lang.Aspects.aspectOf(java.lang.Class) throws org.aspectj.lang.NoAspectBoundException] threw exception; nested exception is org.aspectj.lang.NoAspectBoundException: Exception while initializing logging.OutputMessageLoggerAspect: java.lang.NoSuchMethodException: com.cadit.xas.aop.logging.OutputMessageLoggerAspect.aspectOf()



Is there something wrong in the way I use Aspects utility class?



Many thanks in advance,

Andrea
Andy Clement
2012-08-10 15:35:44 UTC
Permalink
I'm afraid the Aspects type will still make calls to
aspectOf/hasAspect methods in the aspect. The Aspects class is
provided so that you can develop in pure java and not get compile time
errors when attempting to call aspectOf()/etc. So you can call
Aspects.aspectOf(Foo.class) and javac will let it through, but the
system will only work at runtime if the annotation style aspect has
been finished off by getting an aspectOf/hasAspect/etc generated into
it (because Aspects.aspectOf(Foo.class) reflectively calls
Foo.aspectOf()).

After compilation with javac, can you not just pass the aspect classes
through ajc to finish them off?
ajc -inpath library.jar -outjar finishedlibrary.jar

cheers,
Andy
Post by Tevoi Andrea
Hi all,
weave an application. I know that because I used java compiler, aspectOf and
hasAspect are not generated, so I tried to use Aspects utility class to
instantiate Aspect classes in Spring.

<bean class="org.aspectj.lang.Aspects" id="outputMessageLogger" factory-method="aspectOf">
<constructor-arg type="java.lang.Class"
value="logging.OutputMessageLoggerAspect "/>
...
Factory method [public static java.lang.Object
org.aspectj.lang.Aspects.aspectOf(java.lang.Class) throws
org.aspectj.lang.NoAspectBoundException] threw exception; nested exception
is org.aspectj.lang.NoAspectBoundException: Exception while initializing
com.cadit.xas.aop.logging.OutputMessageLoggerAspect.aspectOf()
Is there something wrong in the way I use Aspects utility class?
Many thanks in advance,
Andrea
_______________________________________________
aspectj-users mailing list
https://dev.eclipse.org/mailman/listinfo/aspectj-users
Tevoi Andrea
2012-08-13 08:00:58 UTC
Permalink
Thanks Andy for your swift reply.
I've used AspectJ Maven plugin to compile the aspect library and it has solved the problem.

Cheers,
Andrea

-----Messaggio originale-----
Da: aspectj-users-***@eclipse.org [mailto:aspectj-users-***@eclipse.org] Per conto di Andy Clement
Inviato: venerdì 10 agosto 2012 17:36
A: aspectj-***@eclipse.org
Oggetto: Re: [aspectj-users] Using Aspects.aspectOf for Spring DI

I'm afraid the Aspects type will still make calls to aspectOf/hasAspect methods in the aspect. The Aspects class is provided so that you can develop in pure java and not get compile time errors when attempting to call aspectOf()/etc. So you can call
Aspects.aspectOf(Foo.class) and javac will let it through, but the system will only work at runtime if the annotation style aspect has been finished off by getting an aspectOf/hasAspect/etc generated into it (because Aspects.aspectOf(Foo.class) reflectively calls Foo.aspectOf()).

After compilation with javac, can you not just pass the aspect classes through ajc to finish them off?
ajc -inpath library.jar -outjar finishedlibrary.jar

cheers,
Andy
Post by Tevoi Andrea
Hi all,
CTW to weave an application. I know that because I used java compiler,
aspectOf and hasAspect are not generated, so I tried to use Aspects
utility class to instantiate Aspect classes in Spring.
...
<bean class="org.aspectj.lang.Aspects" id="outputMessageLogger" factory-method="aspectOf">
<constructor-arg type="java.lang.Class"
value="logging.OutputMessageLoggerAspect "/>
...
Factory method [public static java.lang.Object
org.aspectj.lang.Aspects.aspectOf(java.lang.Class) throws
org.aspectj.lang.NoAspectBoundException] threw exception; nested
exception is org.aspectj.lang.NoAspectBoundException: Exception while
initializing
com.cadit.xas.aop.logging.OutputMessageLoggerAspect.aspectOf()
Is there something wrong in the way I use Aspects utility class?
Many thanks in advance,
Andrea
_______________________________________________
aspectj-users mailing list
https://dev.eclipse.org/mailman/listinfo/aspectj-users
Loading...