我是 OSGi 的新手。我用谷歌搜索了大约几个小时,但找不到答案。也许我的理解是错误的。所以问题。假设我有一个组件。
<component name="sample.component" immediate="true">
<implementation class="sample.SampleComparator" />
<service>
<provide interface="java.util.Comparator" />
</service>
</component>
在代码中:
ServiceReference[] serviceReferences =
bundleContext.getServiceReferences(
java.util.Comparator.class.getName(), "(name=sample.component)");
但我明白了null
。错误在哪里?过滤器(name=sample.component)
对吗?或者我如何设置服务的 ID 并通过它查找?