可选的捆绑分辨率

Optional bundle resolution

我是 OSGi 新手。我写了 JIRA 插件,它是 Apache Felix Bundle. My bundle uses Sprring Framework RestTemplate and Jackson XML 用于简单的 REST API 调用。

所以我使用其他包(在 OSGi 容器上可用):Apache ServiceMix :: Bundles :: spring-web<Import-Package> 设置为 com.fasterxml.jackson.*; version="[2,3)";resolution:="optional"

我在 OSGi 容器上安装了 jackson-databind, jackson-core and jackson-annotations(全部在版本 2.6.5 中)以提供缺少的可选依赖项。

我的 github.

上提供了完整的源代码

当我安装我的插件时一切正常,但在运行时我收到错误:

2016-03-09 10:47:55,431 http-nio-2990-exec-11 ERROR achomont 647x10800x1 1wof9hv 0:0:0:0:0:0:0:1 /secure/CreateWorklog.jspa [c.a.event.internal.AsynchronousAbleEventDispatcher] There was an exception thrown trying to dispatch event [WorklogCreatedEvent{worklog=com.atlassian.jira.issue.worklog.WorklogImpl2@555b9717}] from the invoker [SingleParameterMethodListenerInvoker{method=public void com.company.soft.mycompany.work.log.plugin.listeners.WorkLogIssueListener.onWorklogEvent(com.atlassian.jira.event.worklog.WorklogEvent), listener=com.company.soft.mycompany.work.log.plugin.listeners.WorkLogIssueListener@7491b5aa}]
java.lang.RuntimeException: com/fasterxml/jackson/core/JsonProcessingException
    at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:54)
    at com.atlassian.event.internal.AsynchronousAbleEventDispatcher.run(AsynchronousAbleEventDispatcher.java:48)
    at com.google.common.util.concurrent.MoreExecutors$DirectExecutorService.execute(MoreExecutors.java:299)
    at com.atlassian.event.internal.AsynchronousAbleEventDispatcher.dispatch(AsynchronousAbleEventDispatcher.java:107)
    at com.atlassian.event.internal.EventPublisherImpl.invokeListeners(EventPublisherImpl.java:160)
    at com.atlassian.event.internal.EventPublisherImpl.publish(EventPublisherImpl.java:79)
    at java.util.Optional.ifPresent(Optional.java:159)
    at com.atlassian.jira.issue.worklog.DefaultTimeTrackingIssueUpdater.dispatchEvent(DefaultTimeTrackingIssueUpdater.java:242)
    at com.atlassian.jira.issue.worklog.DefaultTimeTrackingIssueUpdater.doUpdate(DefaultTimeTrackingIssueUpdater.java:221)
    at com.atlassian.jira.issue.worklog.DefaultTimeTrackingIssueUpdater.updateIssue(DefaultTimeTrackingIssueUpdater.java:202)
    at com.atlassian.jira.issue.worklog.DefaultTimeTrackingIssueUpdater.updateIssueOnWorklogCreate(DefaultTimeTrackingIssueUpdater.java:89)
    at com.atlassian.jira.issue.worklog.DefaultWorklogManager.create(DefaultWorklogManager.java:68)
    at com.atlassian.jira.bc.issue.worklog.DefaultWorklogService.create(DefaultWorklogService.java:724)
    at com.atlassian.jira.bc.issue.worklog.DefaultWorklogService.createAndAutoAdjustRemainingEstimate(DefaultWorklogService.java:381)
    at com.atlassian.jira.web.action.issue.CreateWorklog.doExecute(CreateWorklog.java:100)
    ... 1 filtered
    at com.atlassian.jira.action.JiraActionSupport.execute(JiraActionSupport.java:63)
    ... 7 filtered
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    ... 74 filtered
    at com.atlassian.labs.httpservice.resource.ResourceFilter.doFilter(ResourceFilter.java:59)
    ... 38 filtered
    at com.atlassian.jira.security.JiraSecurityFilter.doFilter(JiraSecurityFilter.java:70)
    ... 37 filtered
    at com.atlassian.fastdev.AutoReloadFilter.doFilter(AutoReloadFilter.java:63)
    ... 55 filtered
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException
    at com.company.soft.mycompany.connector.impl.MycompanyConnectorImpl.sendWorklogData(MycompanyConnectorImpl.java:80)
    at com.company.soft.mycompany.connector.impl.MycompanyConnectorImpl.sendWorklogData1(MycompanyConnectorImpl.java:96)
    at com.company.soft.mycompany.connector.impl.MycompanyConnectorImpl.sendWorklogDataWithCheck(MycompanyConnectorImpl.java:100)
    at com.company.soft.mycompany.connector.impl.MycompanyConnectorImpl.sendAddWorkLogData(MycompanyConnectorImpl.java:65)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    ... 1 filtered
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:56)
    at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:60)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:70)
    at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:53)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.eclipse.gemini.blueprint.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:57)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at com.sun.proxy.$Proxy2639.sendAddWorkLogData(Unknown Source)
    at com.company.soft.mycompany.work.log.plugin.listeners.WorkLogIssueListener.sendWorkLogData(WorkLogIssueListener.java:115)
    at com.company.soft.mycompany.work.log.plugin.listeners.WorkLogIssueListener.onWorklogEvent(WorkLogIssueListener.java:63)
    ... 3 filtered
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:36)
    ... 235 more
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.JsonProcessingException not found by org.apache.servicemix.bundles.spring-web [13]
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
    at org.apache.felix.framework.BundleWiringImpl.access0(BundleWiringImpl.java:75)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 267 more

看起来像 OSGi 容器 不知道 com.fasterxml.jackson.core 现在可用了。

  1. 我应该重新加载 Apache ServiceMix :: Bundles :: spring-web 吗?
  2. 或者我可能需要用另一种方式来做?

我希望有人能帮助我。

如果您的包有一个可选的导入,并且您允许它在没有将导入连接到导出器的情况下解析,那么这种情况将一直持续到您执行 "refresh" 操作。 OSGi 尝试让 bundle import/export 布线尽可能保持静态,因为重新计算的成本很高,而且它还会强制 bundle 重新启动。

因此,如果您希望 OSGi 连接到现在可用的导入,则需要刷新。这可以在 Gogo shell 中通过键入 refresh 命令来完成。