Osgi 如何引用实现给定接口的所有组件?

Osgi 如何引用实现给定接口的所有组件?,osgi,apache-felix,equinox,declarative-services,Osgi,Apache Felix,Equinox,Declarative Services,我正在EclipseEquinoxOSGi环境中使用ApacheFelix服务组件运行时(SCR) 声明了几个组件来实现接口org.example.Producer,如: <?xml version="1.0" encoding="UTF-8"?> <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.example.ProducerA"> <implementat

我正在EclipseEquinoxOSGi环境中使用ApacheFelix服务组件运行时(SCR)

声明了几个组件来实现接口
org.example.Producer
,如:

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.example.ProducerA">
    <implementation class="org.example.ProducerA"/>
    <service>
        <provide interface="org.example.Producer"/>
    </service>
</scr:component>

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.example.ProducerB">
    <implementation class="org.example.ProducerB"/>
    <service>
        <provide interface="org.example.Producer"/>
    </service>
</scr:component>
但这会在运行时产生错误。SCR似乎在其搜索过滤器中包含一个组件名称:

!ENTRY org.eclipse.equinox.ds 1 0 2015-06-22 11:31:31.781
!MESSAGE Could not bind a reference of component org.example.ConsumerA. The reference is: Reference[name = org.example.Producer, interface = org.example.Producer, policy = dynamic, cardinality = 0..n, target = null, bind = bindProducer, unbind = unbindProducer]
正如您在错误消息中看到的,它正在显式搜索名为
org.example.Producer
的组件。但是上面列出的组件都没有这个名称(
org.example.ProducerA
org.example.ProducerB


所以问题是,我如何通过忽略组件名称来动态引用为给定接口提供实现的组件?

正如尼尔·巴特利特指出的那样,我被提到的日志消息误导了。相应的服务只是花了很长时间启动,但最终它们被正确绑定。

正如尼尔·巴特利特指出的那样,我被提到的日志消息误导了。相应的服务只是花了很长时间才启动,但最后它们被正确绑定。

它没有搜索名为
org.example.Producer
的组件。在任何地方都没有这么说。它正在搜索类型为
org.example.Producer
的服务。您的示例没有明显的错误,您引用的消息也不一定是错误的(毕竟它只是说“message”)。你能看到什么实际效果?是否发布了任何
org.example.Producer
服务?当DS无法绑定到服务时,最常见的原因是该服务不存在!请尝试使用与提供的示例类似的实现。@d33t谢谢,但我已经让它按照您在我的回答中可以看到的那样工作了。它没有搜索名为
org.example.Producer
的组件。在任何地方都没有这么说。它正在搜索类型为
org.example.Producer
的服务。您的示例没有明显的错误,您引用的消息也不一定是错误的(毕竟它只是说“message”)。你能看到什么实际效果?是否发布了任何
org.example.Producer
服务?当DS无法绑定到服务时,最常见的原因是该服务不存在!请尝试使用与提供的示例类似的实现。@d33t谢谢,但我已经让它工作了,正如您在我的回答中所看到的那样。
!ENTRY org.eclipse.equinox.ds 1 0 2015-06-22 11:31:31.781
!MESSAGE Could not bind a reference of component org.example.ConsumerA. The reference is: Reference[name = org.example.Producer, interface = org.example.Producer, policy = dynamic, cardinality = 0..n, target = null, bind = bindProducer, unbind = unbindProducer]