【问题标题】:Unsatisfied reference in OSGi declarative service componentOSGi 声明式服务组件中的不满意引用
【发布时间】:2013-10-27 10:43:38
【问题描述】:

我在 OSGi 声明式服务组件中遇到了不满意的引用问题:

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
    name="com.mycompany.foo.Service"
    immediate="true"
    activate="activate"
    deactivate="deactivate">
<implementation class="com.mycompany.foo.Service"/>
<!-- Other references -->
<reference
        interface="org.osgi.service.http.HttpService"
        name="HttpService"
        cardinality="1..1"
        policy="static"
        bind="setHttpService"
        unbind="unsetHttpService"/>
</scr:component>

我从 Eclipse 启动 OSGi 应用程序,控制台显示服务处于 Unsatisfied 状态:

osgi> ls
All Components:
ID    State            Component Name            Located in bundle
6    Unsatisfied        com.mycompany.foo.Service            com.mycompany.foo(bid=18)

comp 命令报告原因是对org.osgi.service.http 的引用不满足:

osgi> comp 6
Component[
    name = com.mycompany.foo.Service
    ...
    state = Unsatisfied
    references = {
        ...
        Reference[name = HttpService, interface = org.osgi.service.http.HttpService, policy = static, cardinality = 1..1, target = null, bind = setHttpService, unbind = unsetHttpService]
    }
    located in bundle = com.mycompany.foo_1.2.3 [18]
]
Dynamic information :
   *The component is NOT satisfied
   The following references are not satisfied:
     Reference[name = HttpService, interface = org.osgi.service.http.HttpService, policy = static, cardinality = 1..1, target = null, bind = setHttpService, unbind = unsetHttpService]
   Component configurations :
     Configuration properties:
       component.name = com.mycompany.foo.Service
       component.id = 6
     Instances: 

org.osgi.service.http 可用,如packages 命令所示:

osgi> p org.osgi.service.http
org.osgi.service.http; version="1.2.1"<org.eclipse.osgi.services_3.2.100.v20100503 [54]>
  com.mycompany.foo_1.2.3 [18] imports
  org.eclipse.equinox.http.registry_1.1.1.R36x_v20101103 [46] imports
  org.eclipse.equinox.http.servlet_1.1.0.v20100503 [47] imports
  org.eclipse.equinox.http.servletbridge_1.0.200.v20100503 [48] imports

我尝试从服务文档中删除引用,并且服务组件已正确实例化和激活,但没有必要的 HttpService 部分。

非常感谢任何帮助进一步排除故障。

【问题讨论】:

    标签: eclipse osgi apache-felix equinox declarative-services


    【解决方案1】:

    错误是说您的组件需要 HttpService 的实现。您没有可用的。

    “p”命令只报告静态包。您有可用的org.osgi.service.http API 包,但您需要一个实际实现 API 并提供服务的包。

    我建议添加 org.apache.felix.http.jetty 包,其中包含一个易于使用的 HttpService 实现。

    【讨论】:

    • 谢谢尼尔,我现在就试试。应通过org.eclipse.equinox.http.servlet.internal.HttpServiceImpl 提供实现。
    • 这是包中私有的类的名称。你不需要关心这些——你只关心哪个包提供了服务。
    • 原来我的工作区中缺少包。我的项目需要从更广泛的捆绑存储库中挑选最小集合。目标平台需要的捆绑包比我最初选择的捆绑包要多。我猜在这种情况下没有运行时错误是设计使然?
    猜你喜欢
    • 1970-01-01
    • 2012-04-27
    • 1970-01-01
    • 1970-01-01
    • 2018-05-20
    • 1970-01-01
    • 1970-01-01
    • 2011-10-14
    • 2013-10-09
    相关资源
    最近更新 更多