|Re: Spring service publishing to wrong reference arbitrarily [message #676454 is a reply to message #676371]
||Sat, 04 June 2011 14:18
Registered: May 2011
If I understand properly what you're trying to do, you want to have @Qualifier values "cross over" the OSGi boundary between Spring contexts. To my knowledge, there's nothing to directly support that. The Spring DM reference (either 1.x or 2.x) doesn't even mention qualifiers, and in my testing, I've seen no evidence that a bean's qualifier value is added to the exported service in any way, though that seems like it would be convenient. Maybe you should file a feature request on Spring DM for that?|
You're seeing seemingly indeterminate service importing behavior in your <osgi:reference> tags because the only constraint you're giving it is the interface that the service needs to implement. The id attribute of osgi:reference has no role in determining which service to select. It's just the id of the bean that the service is exported as. Therefore you're asking the OSGi container for the first service it finds that satisfies the given interface, where "first" would be governed by OSGi's service selection algorithm. Specifically:
"If multiple such service objects exist, the service object with the highest SERVICE_RANKING is returned. If there is a tie in ranking, the service object with the lowest SERVICE_ID (the service object that was registered first) is returned." --OSGi Service Platform Release 4, Version 4.3, Section 5.2.8.
In the meantime, I think you could get what you want by using the bean-name attribute of osgi:reference. That restricts the imported service by the name of the Spring bean that was exported. The bean name *is* a property of the exported service, stored in the service property "org.springframework.osgi.bean.name". Personally, I'd try not to use it, as it's basically by-name bean wiring, where I always find by-type + qualifier to be a much better model, and OSGi itself is very by-type-oriented.
The only other option I can think of would be to add custom service properties when you export the service using the <service-properties> element of <osgi:service> and then use a filter expression on your <osgi:reference>.
Powered by FUDForum
. Page generated in 0.03166 seconds