In our project (Osgi, Spring-Dm, Apache-Felix) we are having some issue on production when BundleContext.getService() return null. It happens very seldom, and not at the start, so it's not a misconfiguration problem.
An alternative could be using ServiceTracker to locate the service, but because the error is quite rare I'm not sure if changing it would solve the situation.
The OSGi-specification says that the method returns
- A service object for the service associated with reference
- or null if
- the service is not registered
- the service object returned by a ServiceFactory does not implement the classes under which it was registered
- the ServiceFactory threw an exception
My first guess would be that the service is not registered.
By the way, using Spring-DM should make most programmatic accesses to the service registry unneccessary. At least in our companies these calls have been generally forbidden and are only allowed in lower level technical code.