0

<?xml version="1.0" encoding="UTF-8"?> <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="sensor_test"> <implementation class="test.sensor.version1.serviceImpl.SensorServiceImpl"/> <service> <provide interface="test.sensor.version1.serviceInterface.SensorServiceInterface"/> </service> <reference bind="setOntologyService" cardinality="0..1" interface="test.ontology.version1.serviceinterface.OntologyServiceInterface" name="OntologyServiceInterface" policy="dynamic" unbind="unsetOntologyService"/> </scr:component>

对于上面显示的内容,可以在同一组件中提供和引用服务吗?例如,有两个捆绑包 A 和 B。A 提供服务供 B 使用,B 也提供服务供 A 使用。这种情况我该怎么办?

4

1 回答 1

1

这似乎很好,因为服务引用既是可选的又是动态的。

如果您定义了一个循环依赖,其中引用都是强制性的,那么 DS 将报告错误。必须有一种方法首先创建一个组件,并且通过强制引用,在创建另一个组件之前都不能创建任何组件(但是,第三个捆绑包“C”可以注册满足其中一个组件的服务)。

使用可选/动态引用,DS 可以构造一个未绑定引用的组件,然后构造另一个组件并将其注入第一个组件。

于 2010-12-19T23:16:26.727 回答