java - 当为 osgi 使用声明性服务时,我可以在同一组件中提供和引用服务吗?

标签 java components service osgi declarative

<?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>

如上所示,在同一个组件中提供和引用服务可以吗? 例如,有两个bundle A和B,A提供服务供B使用,B也提供服务供A使用。遇到这种情况我该怎么办?

最佳答案

这似乎完全没问题,因为服务引用既是可选的又是动态的。

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

通过可选/动态引用,DS 可以构造一个未绑定(bind)引用的组件,然后构造另一个组件并将其注入(inject)回第一个组件。

关于java - 当为 osgi 使用声明性服务时,我可以在同一组件中提供和引用服务吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4478781/

相关文章:

java - 不使用域管理员用户调用 Google 服务帐户

java - cvc-complex-type.2.4.c : The matching wildcard is strict, 但找不到元素 'property' 的声明

Joomla:多次覆盖类别博客输出?

java - Wicket - 实现复杂组件的最佳方式

silverlight-4.0 - 我可以购买Silverlight的上下文菜单控件吗?

java - 定期刷新大对象

java - 我正在开发在后台服务上运行音乐的音乐播放器应用程序,当我离开该应用程序时,媒体播放器停止

java - 如何为android绑定(bind)多个不同的服务?

java - Java多线程生产者/消费者死锁

Android 从 intentservice 共享 intent