Use Spring AOP inside a server plugin

Hi everyone,
I’m trying to use Spring AOP inside my Confluence server plugin but so far I had no luck.
I added the <aop:aspectj-autoproxy /> element in the plugin context XML (with the related schema) but on install I get the following error:

java.lang.NoClassDefFoundError: Could not initialize class org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory

Do I need to add any dependency inside the pom.xml?


1 Like

Hi, @francesco.stefanini.

I have not personally tried adding aspectj but based on the error you got, it does seem you need to add it as a dependency inside the pom. Should it return a similar error still, look into Import-Package inside the pom to add the necessary classes.


Hi @iragudo, thanks for the tip!
I tried several combinations, none of them worked so far :smile:

If I add the org.springframework.aop package into Import-Package it says missing requirement [...] (osgi.wiring.package=org.aspectj.lang.annotation). I tried to add that package too but nothing happened, so I suppose it’s not exposed as an OSGi bundle, right?

After that I tried to add aspectjweaver as a compile dependency: in that case it said missing requirement [...] (osgi.wiring.package=com.bea.jvm) and again there’s no way to import that package.

So I tried with the aspectjrt dependency instead and the error changed a bit: now it says java.lang.ClassNotFoundException: org.aspectj.lang.annotation.Around not found by org.apache.servicemix.bundles.spring-aop.

I’m out of ideas… It looks like there’s always a missing piece that doesn’t get exported by Confluence therefore there’s no way to use AOP inside a plugin :worried: (but I hope I’m wrong :slight_smile: )

If you have any other suggestions I’m all hears!


P.S: i’m using Spring Scanner v2, since I’m targetting Confluence 6.0+… I don’t know if it matters.

Hi @francesco.stefanini,

I ran into a similar issue using AspectJ. Older versions of org.aspectj:aspectjweaver came with an own com.bea.jvm package. The current version does not include it any longer. Afaik the last version including the package was 1.5.4.

The log output for failed OSGi wiring included a link to This side suggest to have a look at the Felix web console to find out if there is a bundle serving the necessary package.

I did not find anything helpful there. I’m not even sure if it was working correctly. If you are able to use it and extract something useful please let me know.

You may be interested in the article Spring Java-based configuration and AOP in Jira plugins .