Java OSGiFelix获取服务

Java OSGiFelix获取服务,java,osgi,Java,Osgi,我已使用两个felix示例注册了两项服务: 在第一个包中,我用代码注册了一个服务 Hashtable<String, String> props = new Hashtable<String, String>(); props.put("Language", "English"); context.registerService(DictionaryService.class.getName(), new DictionaryImpl1(), props)

我已使用两个felix示例注册了两项服务:

第一个包中,我用代码注册了一个服务

Hashtable<String, String> props = new Hashtable<String, String>();
    props.put("Language", "English");
    context.registerService(DictionaryService.class.getName(), new DictionaryImpl1(), props);
参考长度为1,而不是2

当我注册两个服务时,它们用代码在一个包中实现一个接口

ServiceReference[] refs = 
        context.getServiceReferences(DictionaryService.class.getName(), "(Language=*)");
Hashtable<String, String> props = new Hashtable<String, String>();
props.put("Language", "English");
context.registerService(DictionaryService.class.getName(), new DictionaryImpl1(), props);
Hashtable<String, String> props = new Hashtable<String, String>();
props.put("Language", "Chinese");
context.registerService(DictionaryService.class.getName(), new DictionaryImpl2(), props);
我可以得到两份推荐信

添加信息。

<dependency>
    <groupId>org.apache.felix</groupId>
    <artifactId>org.apache.felix.framework</artifactId>
    <version>5.6.1</version>
</dependency>
refList的大小是2

第3595行

if (!Util.isServiceAssignable(bundle, ref))
{
    refIter.remove();
}

它将删除最后一个bundle注册的service ref。

有什么问题,您有什么问题?我不明白你想说什么“只有一个引用,为什么?”@Erwin Bolwidt更新问题,我只想获得不同捆绑包中的所有服务哪个resigter。在查询服务注册表之前,你是否确保两个捆绑包都已激活(假设你在其捆绑包激活器中注册了两个服务)?@erdal.karaca是的,我确定。那么,在osgi控制台中键入“ss”时,您可以看到这两个捆绑包都处于活动状态?此外,这两种激活剂都被称为?
<dependency>
    <groupId>org.apache.felix</groupId>
    <artifactId>org.apache.felix.framework</artifactId>
    <version>5.6.1</version>
</dependency>
final Collection refList = m_registry.getServiceReferences(className, filter);
if (!Util.isServiceAssignable(bundle, ref))
{
    refIter.remove();
}