Home » Eclipse Projects » Virgo » How do you set up Spring AOP/AspectJ/Virgo
How do you set up Spring AOP/AspectJ/Virgo [message #608511] |
Thu, 02 September 2010 19:20  |
Eclipse User |
|
|
|
Is there a good tutorial/description of what one needs to do to set up AspectJ load time weaving alongside Spring AOP in Eclipse Virgo?
I see mention that this is feasible, but don't see anything documentation.
Thanks in advance
|
|
| | | | | | | |
Re: How do you set up Spring AOP/AspectJ/Virgo [message #757334 is a reply to message #757153] |
Thu, 17 November 2011 13:47   |
Eclipse User |
|
|
|
Martin W. wrote on Wed, 16 November 2011 14:33
Is there a way to weave aspects across multiple Virgo bundles?
Hi again,
After doing a lot of reading I'm assuming it is possible. But just to be sure, can anyone tell me if it is possible ACROSS BUNDLES (define aspect in one bundle, weave into class of another bundle)?
If so, do I have to make any modifications to the Virgo configuration for LTW to work across bundles? I did not find any tutorials specifically for Virgo, and as I've never worked with other OSGI frameworks, it's difficult for me to use other tutorials here....
Furthermore, is it possible without any modifications whatsoever in the bundle where the aspect should be woven? (again, I'm assuming it should work)
However, after spending like a week of time, I could not get it work. Even without the restriction of not making modifications in the 2nd bundle.
Unfortunately the source-code in bug 333646 is not available completely anymore....
I'm using Virgo 3.0.1.RELEASE (fresh installation), my IDE is SpringSource Tool Suite. Here's what I did:
1. create an 'EclipseRT OSGI Bundle' "base"
in there is one interface ("IProfiler") defining a method void execute() -- writes to System.out
the package is being exported
2. create another bundle "component"
one class ("BarProfiler"), implementing IProfiler. and one class "BarProfilerCaller". BarProfilerCaller has a field of type IProfiler.
In the spring configuration XML file, both classes are being instantiated, and setProfiler in BarProfilerCaller is called, which immediately calls execute().
3. 3rd bundle: "aspect1"
MyAspect.aj:
package aspect;
public aspect MyAspect {
pointcut all() : execution(* *.*(..)) && !within(MyAspect);
after() returning : all() {
System.out.println("Hello World from MyAspect as well....");
}
}
I get a warning there: "advice defined in aspect1.MyAspect has not been applied [Xlint:adviceDidNotMatch]"
aop.xml:
<aspectj>
<weaver>
<include within="**"/>
</weaver>
<aspects>
<aspect name="aspect.MyAspect"/>
</aspects>
</aspectj>
spring/aspect-context.xml:
<beans
.....
<!-- <aop:aspectj-autoproxy/> -->
<context:load-time-weaver aspectj-weaving="on"/>
</beans>
MANIFEST.MF:
Manifest-Version: 1.0
Bundle-Version: 1.0.0
Bundle-Name: Aspect POC
Bundle-ManifestVersion: 2
Bundle-SymbolicName: aspect1
Import-Package: base,
org.aspectj.weaver;version="[1.6.10.RELEASE,1.6.10.RELEASE]",
org.aspectj.weaver.ast;version="[1.6.10.RELEASE,1.6.10.RELEASE]",
org.aspectj.weaver.bcel;version="[1.6.10.RELEASE,1.6.10.RELEASE]",
org.aspectj.weaver.bcel.asm;version="[1.6.10.RELEASE,1.6.10.RELEASE]",
org.aspectj.weaver.internal.tools;version="[1.6.10.RELEASE,1.6.10.RELEASE]",
org.aspectj.weaver.loadtime;version="[1.6.10.RELEASE,1.6.10.RELEASE]",
org.aspectj.weaver.loadtime.definition;version="[1.6.10.RELEASE,1.6.10.RELEASE]",
org.aspectj.weaver.ltw;version="[1.6.10.RELEASE,1.6.10.RELEASE]",
org.aspectj.weaver.model;version="[1.6.10.RELEASE,1.6.10.RELEASE]",
org.aspectj.weaver.patterns;version="[1.6.10.RELEASE,1.6.10.RELEASE]",
org.aspectj.weaver.reflect;version="[1.6.10.RELEASE,1.6.10.RELEASE]",
org.aspectj.weaver.tools;version="[1.6.10.RELEASE,1.6.10.RELEASE]",
org.osgi.framework,
org.osgi.framework.hooks.weaving;version="[1.0.0,1.0.0]",
org.springframework.aop;version="[3.0.5.RELEASE,3.0.5.RELEASE]",
org.springframework.aop.framework;version="[3.0.5.RELEASE,3.0.5.RELEASE]",
org.springframework.beans.factory.config;version="[3.0.5.RELEASE,3.0.5.RELEASE]",
org.springframework.context.weaving;version="[3.0.5.RELEASE,3.0.5.RELEASE]",
org.springframework.core;version="[3.0.5.RELEASE,3.0.5.RELEASE]",
org.springframework.instrument.classloading;version="[3.0.5.RELEASE,3.0.5.RELEASE]"
Import-Bundle: com.springsource.net.sf.cglib;version="2.2.0"
Eclipse-SupplementBundle: base,
component
When i deploy the bundles: for base and component I get something like
[2011-11-17 19:36:03.996] INFO region-dm-8 o.e.virgo.kernel.dmfragment.internal.LoadTimeWeaverPostProcessor Load-time weaving not enabled for bundle 'component_1.0.0 [124]',
(unless i add "<context:load-time-weaver aspectj-weaving="on" />" to the spring config. - but then i don't get the output of the aspect either...)
For the aspect bundle I get:
[2011-11-17 19:40:44.708] INFO region-dm-2 o.e.virgo.kernel.dmfragment.internal.LoadTimeWeaverPostProcessor Found load-time weaver bean for bundle 'aspect1_1.0.0 [124]'. Switching to ServerLoadTimeWeaver.
What am I missing?
Thanks in advance for any hints!
All the best,
Martin
[Updated on: Fri, 18 November 2011 03:35] by Moderator
|
|
|
Re: How do you set up Spring AOP/AspectJ/Virgo [message #757421 is a reply to message #757334] |
Fri, 18 November 2011 07:02   |
Eclipse User |
|
|
|
Hi
Martin W. wrote on Thu, 17 November 2011 19:47
But just to be sure, can anyone tell me if it is possible ACROSS BUNDLES (define aspect in one bundle, weave into class of another bundle)?
If so, do I have to make any modifications to the Virgo configuration for LTW to work across bundles? I did not find any tutorials specifically for Virgo, and as I've never worked with other OSGI frameworks, it's difficult for me to use other tutorials here....
Yes it is possible to define an aspect in one bundle and weave code into a class located in another bundle. You already mentioned https://bugs.eclipse.org/bugs/show_bug.cgi?id=333646 there is everything you need to get it running. All the needed code is in the attachments, there isn't anything missing as far as I can tell.
Martin W. wrote on Thu, 17 November 2011 19:47
Furthermore, is it possible without any modifications whatsoever in the bundle where the aspect should be woven? (again, I'm assuming it should work)
It depends. As long as you don't introduce new dependencies it should work w/o any modification. As soon as you're introducing new dependencies to the target bundle that aren't covered by the package import/require bundle headers the problems will start. You can work around that with dynamic package imports but that could cause other troubles and it means you have to touch the target bundles at least once. Furthermore it will limit you as you have to follow a certain package strucutre (unless you just import everything).
With the latest OSGi spec 4.3 (please correct me if I'm wrong) a new approach has been introduced using a whiteboard pattern for bytecode weaving. You can find some information about that on http://www.slideshare.net/mfrancis/bytecode-weaving-in-osgi-enhance-your-classes-not-your-dependency-graph-tim-ward. I haven't tried to use it with Virgo yet so I can't tell you if it's already working or not. But it provides a way to change the manifest of the target platform w/o touching the bundle itself so I think that's pretty much what you're looking for. Afaik the Apache Aries project is using it for their persistence stuff so you may find some example code there on how to use it.
|
|
|
Re: How do you set up Spring AOP/AspectJ/Virgo [message #757499 is a reply to message #757421] |
Fri, 18 November 2011 11:19   |
Eclipse User |
|
|
|
Hi,
Thank you very much Frieder for you reply! 
I tried the example code from bug 333646. Unfortunatly it does not work for me.
First of all I had make a few modifications: (see attachments)
- changed required version numbers of imports in MANIFESTs (removed the maximum)
- added some imports (quite some of them are probably not required, but I suppose they won't harm)
- replaced MyAspect.aj with an equivalent MyAspect.java (somehow with the .aj I got compile errors)
Still, it seems that the Aspect is not detected correctly, when the bundles are deployed. I'm deploying the bundles manually (i.e. no PAR or plan), and i tried different orders.
There is no mentioning of aop.xml or MyAspect anywhere in the logs (also attached). Like sven and rob mentioned earlier, I don't see any output on System.out from MyAspect either. 
Also, in the logs it says
[2011-11-18 17:09:05.209] INFO region-dm-12 o.e.virgo.kernel.dmfragment.internal.LoadTimeWeaverPostProcessor Load-time weaving not enabled for bundle 'org.example.spring_1.0.0 [117]',
I'd appreciate if somebody could take a look into it...
All the best,
Martin
EDIT 2011-11-21: In the previous upload I forgot the @Aspect annotation. Uploaded a new version, but still the same behaviour... 
[Updated on: Mon, 21 November 2011 04:33] by Moderator
|
|
| | | | | | |
Goto Forum:
Current Time: Tue Jul 22 12:49:30 EDT 2025
Powered by FUDForum. Page generated in 0.25780 seconds
|