【问题标题】:How to configure OSGI Declarative Service scope?如何配置 OSGI 声明式服务范围?
【发布时间】:2014-12-10 22:56:44
【问题描述】:

谁能解释一下如何将 OSGI DS 配置为单例? 我使用 Equinox 作为 OSGi 容器。

SCR 组件

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="Simple Dictionary">
   <implementation class="foo.bar.services.DictionaryImpl"/>
   <service>
      <provide interface="foo.bar.services.Dictionary"/>
   </service>
</scr:component>

OSGI 控制台输出

osgi> 服务 (objectClass=foo.bar.services*)
{foo.bar.services.Dictionary}={
component.name=简单字典,
组件.id=0,
service.id=51,
service.bundleid=7,
service.scope=bundle
}
“由捆绑注册:” foo.bar.services_1.0.0.qualifier [7]
“没有使用服务的捆绑包。”

【问题讨论】:

    标签: java osgi declarative-services


    【解决方案1】:

    除非你说servicefactory="true",否则它是一个单例。 DS 将始终使用 SerivceFactory 来注册组件的服务。这允许实际的组件创建和激活是惰性的。所以你永远不会在注册的服务上看到 service.scope=singleton。

    对于 DS 1.3,servicefactory 将替换为 scope,但上述关于 DS 始终使用 ServiceFactory 的说法仍然正确。

    【讨论】:

    • 最新版本的 apache felix 是否支持 DS 1.3?正如我所看到的en.wikipedia.org/wiki/… 确实如此。但我找不到如何使用范围的信息。
    猜你喜欢
    • 1970-01-01
    • 2011-05-01
    • 1970-01-01
    • 2012-04-27
    • 2013-10-09
    • 2018-05-20
    • 1970-01-01
    • 2011-09-03
    • 1970-01-01
    相关资源
    最近更新 更多