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



Reply via email to