Reputation:
I am newbie in OSGi. I have googled about a few hours but couldn't find the answer. Maybe my understanding is wrong. So the problem. Lets suppose I have a component.
<component name="sample.component" immediate="true">
<implementation class="sample.SampleComparator" />
<service>
<provide interface="java.util.Comparator" />
</service>
</component>
and in code:
ServiceReference[] serviceReferences =
bundleContext.getServiceReferences(
java.util.Comparator.class.getName(), "(name=sample.component)");
But I get null
. Where is the mistake? Is filter (name=sample.component)
right? Or how can I set id of the service and lookup by it?
Upvotes: 3
Views: 932
Reputation: 6046
The name of the service property is "component.name", not "name".
If you do this, it will work:
getServiceReferences(java.util.Comparator.class.getName(),"(component.name=sample.component)");
Upvotes: 6