Osgi 声明式服务条件绑定
我有这样的场景,我有三个提供相同接口的声明性服务(比如说一个阅读器接口,我有 readerimpl1-database- readerimpl2-flat file- readerimpl3-memory)。我想要一个仅绑定到数据库实现的消费者。在组件定义中,我们给它一个名称,因此我非常确定该名称在注册表中,因此如果我要添加激活方法,我可以使用该名称从组件上下文中查找。
我想通过使用服务名称作为参数来尝试通过绑定/取消绑定。我非常确定组件引用元素中的“目标”参数可用于执行此操作,但我还没有找到如何使用它。
还有其他人这样做过吗?
这类似于使用 @Reference(映射名称=“foo”)
I have this scenario, I have three declarative services that provide the same interface (say a reader interface and I have readerimpl1-database- readerimpl2-flat file- readerimpl3-memory). I want to have a consumer that binds only to the database implementation. In the component definition we give it a name so I am pretty sure that the name is in the registry so if I were to add an activate method I can lookup from the component context using the name.
I want to try to it via the bind/unbind though using the service name as the parameter. I am pretty sure that the "target" parameter in the component reference element can be used to do this but I have not found how to use it.
Has anyone else done this?
This would be similar to using
@Reference(mapped-name="foo")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目标只是一个 OSGi 过滤器。您可以使用它按任何服务属性进行过滤。因此,如果您的服务具有名为
backend
且值为file
或database
的属性,则可以与以下目标绑定:以及具有数据库后端的服务其本身将注册为:
Target is simply an OSGi filter. You can use it to filter by any service property. So, if your services have property named
backend
with valuesfile
ordatabase
, you can bind with the following target:And the service with database backend itself will register as: