在 OSGi 包中使用 Spring AOP [英] Use Spring AOP in OSGi bundle

查看:42
本文介绍了在 OSGi 包中使用 Spring AOP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Spring AOP 进行日志记录.我已经设置了日志包,以及其中的 OSGi 服务.

I am trying to use the Spring AOP for logging purposes. I have set up the logging bundle, and the OSGi service in it.

我有其他 OSGi 包,它使用日志包中的服务作为 OSGi 引用.

I have other OSGi bundle which uses the service from logging bundle as a OSGi reference.

日志包部署到 Apache Karaf 并运行.我无法部署我的其他包.

The logging bundle is deployed into Apache Karaf and running. I can not get my other bundle deployed.

我的 bundle 中的 spring 配置是这样的:

The spring configuration in my bundle is like that:

<osgi:reference id="loggingIterceptor" interface="com.groupgti.commons.log.LoggingInterceptorAdvice"/>
<aop:config>
    <aop:pointcut id="logger" expression="@annotation(com.groupgti.esb.assessments.kenexa.log.InOutLogger)"/>
    <aop:advisor pointcut-ref="logger" advice-ref="loggingIterceptor"/>
</aop:config>

当我尝试启动我的捆绑包时,它给了我:

When I am trying to start my bundle it gives me:

java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
    at java.lang.Class.getDeclaredMethods0(Native Method)[:1.6.0_33]
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)[:1.6.0_33]
    at java.lang.Class.getDeclaredMethods(Class.java:1791)[:1.6.0_33]
    at org.springframework.core.type.StandardAnnotationMetadata.hasAnnotatedMethods(StandardAnnotationMetadata.java:136)
    at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.checkConfigurationClassCandidate(ConfigurationClassBeanDefinitionReader.java:318)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:175)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:161)
    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.invokeBeanFactoryPostProcessors(AbstractDelegatedExecutionApplicationContext.java:479)[70:org.springframework.osgi.core:1.2.1]
    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.invokeBeanFactoryPostProcessors(AbstractDelegatedExecutionApplicationContext.java:467)[70:org.springframework.osgi.core:1.2.1]
    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.invokeBeanFactoryPostProcessors(AbstractDelegatedExecutionApplicationContext.java:395)[70:org.springframework.osgi.core:1.2.1]
    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$3.run(AbstractDelegatedExecutionApplicationContext.java:281)[70:org.springframework.osgi.core:1.2.1]
    at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)[70:org.springframework.osgi.core:1.2.1]
    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.startRefresh(AbstractDelegatedExecutionApplicationContext.java:247)[70:org.springframework.osgi.core:1.2.1]
    at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.stageOne(DependencyWaiterApplicationContextExecutor.java:214)[71:org.springframework.osgi.extender:1.2.1]
    at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.refresh(DependencyWaiterApplicationContextExecutor.java:169)[71:org.springframework.osgi.extender:1.2.1]
    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.refresh(AbstractDelegatedExecutionApplicationContext.java:175)[70:org.springframework.osgi.core:1.2.1]
    at org.springframework.osgi.extender.internal.activator.ContextLoaderListener$2.run(ContextLoaderListener.java:716)[71:org.springframework.osgi.extender:1.2.1]
    at java.lang.Thread.run(Thread.java:662)[:1.6.0_33]
Caused by: java.lang.ClassNotFoundException: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException not found by org.springframework.aop [57]
    at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:787)
    at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:71)
    at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1768)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)[:1.6.0_33]

我已将 maven 依赖项添加到我的 pom.xml 中:

I have added the maven dependency into my pom.xml:

<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.6.2</version>
</dependency>

仍然没有解决问题.我在这里缺少什么?

Still does not solves the problem. What I am missing here?

推荐答案

问题是您正在导入的 Maven 依赖项没有正确的 OSGI 清单.清单中缺少与所有其他 OSGI 标记相邻的 Export-Package 标记.

The problem is that the Maven dependency you are importing does not have a proper OSGI manifest. The Export-Package tag, next to all other OSGI tags, is missing from the manifest.

因此,org.aspectj.weaver.reflect 包不会被导出,在 OSGI 中这意味着该包中的类不会被其他包知道.因此,ClassNotFoundException.

So, the org.aspectj.weaver.reflect package is not exported, and in OSGI this means the classes in that package will not be known to other bundles. Hence the ClassNotFoundException.

要解决您的问题,请将您的依赖项替换为以下内容:

To solve your problem, replace your dependency with the following:

<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>com.springsource.org.aspectj.weaver</artifactId>
    <version>1.6.2.RELEASE</version>
</dependency>

springsource jars 基本上是官方版本的重新打包,但有一个适当的 osgi manifest.

The springsource jars are basically repackages of the official versions, but with a proper osgi manifest.

这篇关于在 OSGi 包中使用 Spring AOP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆