OSGi/Felix 声明式服务:如何过滤要绑定的服务? [英] OSGi/Felix Declarative Services: How to filter the services to be bound?

查看:29
本文介绍了OSGi/Felix 声明式服务:如何过滤要绑定的服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Apache Felix 及其声明式服务 (SCR) 来连接捆绑包之间的服务依赖项.

I am using Apache Felix and its Declarative Services (SCR) to wire the service dependencies between bundles.

例如,如果我需要访问 java.util.Dictionary,我可以说以下内容让 SCR 提供:

For example, if I need access to a java.util.Dictionary I can say the following to have SCR provide one:

/**
* @scr.reference name=properties interface=java.util.Dictionary
*/

protected void bindProperties(Dictionary d) {
}

protected void unbindProperties(Dictionary d) {
}

现在,我有多个可用的 Dictionary 服务,我想使用name"服务属性来过滤它们(我只想要name=myDictionary").我可以用代码来做到这一点(使用 ServiceTracker),但我宁愿在 @scr 注释中指定过滤器.

Now, I have more than one Dictionary service available, and I want to filter them using the "name" service property (I only want "name=myDictionary"). I can do that with code (using a ServiceTracker), but I'd rather specify the filter in the @scr annotation instead.

推荐答案

我认为

target="(name=myDictionary)"

应该在 @scr.reference 注释中起作用.请参阅 http://felix.apache.org/site/apache-felix-maven-scr-plugin.html

should do the trick in the @scr.reference annotation. See http://felix.apache.org/site/apache-felix-maven-scr-plugin.html

这篇关于OSGi/Felix 声明式服务:如何过滤要绑定的服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆