Home » Eclipse Projects » Virgo » How do you set up Spring AOP/AspectJ/Virgo
| | |
Re: How do you set up Spring AOP/AspectJ/Virgo [message #684900 is a reply to message #676583] |
Thu, 16 June 2011 12:57 |
|
I am also struggling with getting LTW with Virgo 2.1.0 running. Here's what I have thus far:
* I created a bundle A with a spring context in META-INF/spring that contains the <context:load-time-weaver aspectj-weaving="on" /> element
* The same (!) bundle contains a META-INF/aop.xml that defines the aspects to be loaded and the classes to consider for LTW
* I see this in my logs when the bundle starts:
[2011-06-16 14:50:05.536] region-dm-6 o.e.virgo.kernel.dmfragment.internal.LoadTimeWeaverPostProcessor Found load-time weaver bean for bundle 'foo.bar_1.1.0.SNAPSHOT [175]'. Switching to ServerLoadTimeWeaver.
My aop.xml looks like this:
<aspectj>
<weaver options="-verbose -debug">
<include within="**"/>
</weaver>
<aspects>
<aspect name="foo.ProfileAspect"/>
</aspects>
</aspectj>
But - I don't get any output from my profiling aspect. No information from the weaver (debug/verbose) output. Am I missing anything here? Apart from the above-mentioned configuration, I didn't add anything to my Spring context or to the Virgo installation. Note that the aspect class is exported by another bundle that was loaded before the above-mentioned bundle (the packages are correctly resolved)...
Thanks in advance
Sven
|
|
| |
Re: How do you set up Spring AOP/AspectJ/Virgo [message #728073 is a reply to message #727757] |
Thu, 22 September 2011 13:41 |
Rick Cole Messages: 1 Registered: September 2011 |
Junior Member |
|
|
Has anyone found a solution to this? We have added the context:load-time-weaver to our application context. The behavior I am seeing is that the postProcessBeanFactory() method on the BeanFactoryPostProcessors of the bundle application context is getting called BEFORE the AspectJWeavingEnabler is created. The result is that the postProcessBeanFactory() method on the AspectJWeavingEnabler is never called which I assume means load time weaving is not going to work.
[Updated on: Thu, 22 September 2011 13:42] Report message to a moderator
|
|
| | |
Re: How do you set up Spring AOP/AspectJ/Virgo [message #757334 is a reply to message #757153] |
Thu, 17 November 2011 18:47 |
Martin W. Messages: 8 Registered: June 2011 |
Junior Member |
|
|
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 08:35] Report message to a moderator
|
|
|
Re: How do you set up Spring AOP/AspectJ/Virgo [message #757421 is a reply to message #757334] |
Fri, 18 November 2011 12:02 |
Frieder Heugel Messages: 61 Registered: October 2010 Location: Basel, CH |
Member |
|
|
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 16:19 |
Martin W. Messages: 8 Registered: June 2011 |
Junior Member |
|
|
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 09:33] Report message to a moderator
|
|
| | | | |
Re: How do you set up Spring AOP/AspectJ/Virgo [message #870530 is a reply to message #676583] |
Tue, 08 May 2012 14:46 |
Martin W. Messages: 10 Registered: June 2011 |
Junior Member |
|
|
Matt Fellows wrote on Sun, 05 June 2011 09:43it is as simple this:
1. Add <context:load-time-weaver aspectj-weaving="on"/> to your application context as Glyn mentioned
Hi everybody,
Matt's instructions work for me - but only as long as class and aspect are in the same bundle. But what do I have to do to weave across bundles?
I have exported the package of my aspect, but the aspect is not woven in the other bundle. Adding <context:load-time-weaver aspectj-weaving="on"/> in the other bundle - to "switch to ServerLoadTimeWeaver" - does not help.
Unfortunately my solution (posted on Mon, 21 November 2011) does not work with Virgo 3.5.0.M4.
Can anybody give me some advice?
EDIT: I attached the sample projects from my previous solution --- modified to use the libraries as of Virgo version 3.5.0.M4.
All the best,
Martin
[Updated on: Tue, 08 May 2012 14:56] Report message to a moderator
|
|
| |
Goto Forum:
Current Time: Thu Sep 26 01:40:27 GMT 2024
Powered by FUDForum. Page generated in 0.03793 seconds
|