Hi JB, No I did not try that, but I believe it would work. I was able to find a work around with Spring AOP. I was able to get the aspects working when I defined the aspects in XML configuration instead of using the @Aspect annotation. However, Spring AOP approach as well as embeding AspectJ in the bundle have the problem that it will work just within that one bundle. I need to be able to weave also classes from other bundles. And as far as I know there is no other solution than load-time weaving with AspectJ provided by the framework itself (using the hooks). Or am I missing something and there is some other was how to achieve that? BR Martin
-----Original Message----- From: Jean-Baptiste Onofré <[email protected]> Sent: Wednesday, September 7, 2022 10:06 AM To: [email protected] Subject: Re: Aspectj in Apache Karaf 4.4.1 Hi, I don't use aspectj in Karaf. So, unfortunately, I can't help so much. Did you try to embed aspectj in your spring bundle ? Regards JB On Mon, Sep 5, 2022 at 5:10 PM Martin Zukal <[email protected]> wrote: > > Hello everyone! > > I am sorry to reply to my own email but I would really like to know whether > there is somebody who was able to get aspectj and load-time weaving running > with Apache Karaf. > > I am really stuck on this so any hint would be hihgly appreciated! > > Best Regards > > Martin Zukal > > > > > > From: Martin Zukal <[email protected]> > Sent: Saturday, August 27, 2022 11:42 AM > To: '[email protected]' <[email protected]> > Subject: Aspectj in Apache Karaf 4.4.1 > > > > Hello everyone! > > I am trying to enable aspectj in Apache Karaf version 4.4.1 and I am unable > to get it to work. I have a project based on Spring which I want to run in > Apache Karaf. This project contains the aspects and includes the following > lines in the configuration: > > <context:load-time-weaver aspectj-weaving="on" /> > > <aop:aspectj-autoproxy /> > > Which is why I need aspectj in the runtime. > > What I should probably also mention is that the project uses Gemini Blueprint > version 3.0.0.M01 to publish the Spring services into the OSGi context. > > > > I was not able to find any recent tutorial how to enable aspects in Apache > Karaf so I followed this blog post: > http://dywicki.pl/2011/11/running-aspects-under-osgi-4-2-with-karaf/ and > adapted the procedure slightly. What I did so far is: > > Changed the framework from felix to equinox Placed the three bundles > (org.eclipse.equinox.weaving.aspectj, > org.eclipse.equinox.weaving.caching and > org.eclipse.equinox.weaving.hook) into the system directory Added > entries for the above mentioned bundles to startup.properties > > Apache karaf starts fine with the above described configuration and I can see > all weaving bundles as active in the console > (org.eclipse.equinox.weaving.hook is a fragment so there it says fragment). > > > > However, when I try to deploy the bundle with my Spring project I get the > following exception: > > org.springframework.beans.factory.BeanCreationException: Error > creating bean with name > 'org.springframework.context.config.internalAspectJWeavingEnabler': > Initialization of bean failed; nested exception is > org.springframework.beans.factory.BeanCreationException: Error > creating bean with name 'loadTimeWeaver': Initialization of bean > failed; nested exception is java.lang.IllegalStateException: > ClassLoader > [org.eclipse.gemini.blueprint.util.BundleDelegatingClassLoader] does > NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify > a custom LoadTimeWeaver or start your Java virtual machine with > Spring's agent: -javaagent:spring-instrument-{version}.jar > > I tried to start Apache Karaf with the -javaagent option but it did not help. > > I am coming from Eclipse Virgo and the aspects were working there > quite fine. One of the settings which was needed to add was > > osgi.framework.extensions = org.eclipse.equinox.weaving.hook. > > Is there a possibility how to add this setting to Apache Karaf? > > > > Is there any recent tutorial how to get aspects working in Apache Karaf? I > would really appreciate any help with this topic! > > Best Regards > > Martin Zukal
