OSGi/Felix Declarative Services: How to filter the services to be bound?

依然范特西╮ 提交于 2020-01-03 15:32:17

问题


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

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) {
}

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.


回答1:


I think

target="(name=myDictionary)"

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




回答2:


In standard DS, you can use target attribute of the reference element. In Felix world, where annotations can be used, I don't know what is the equivalent.

The target attribute is an LDAP filter, which matches against the service properties. So, your filter should be:

(name=myDictionary)



来源:https://stackoverflow.com/questions/308813/osgi-felix-declarative-services-how-to-filter-the-services-to-be-bound

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!