1

有人可以解释一下如何将 OSGI DS 配置为单例吗?我使用 Equinox 作为 OSGi 容器。

可控硅元件

<?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> services (objectClass=foo.bar.services*)
{foo.bar.services.Dictionary}={
component.name=Simple Dictionary,
component.id=0,
service.id=51,
service.bundleid=7,
service .scope=bundle
}
"由捆绑注册:" foo.bar.services_1.0.0.qualifier [7]
"没有捆绑使用服务。"

4

1 回答 1

1

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

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

于 2014-10-15T20:18:10.267 回答