0

In Karaf version 3.0.3 i was able to retrieve the ServiceReference object using the below code

ServiceReference serviceReference = 
                (ServiceReference) bundleContext.getServiceReference(CustomService.class.getName());

But in Karaf 4 this code returns null. My service is started i was able to see the service in the service list.

Note: i am trying to retrieve a service which is loaded as a wrapped bundle

Charity
  • 213
  • 1
  • 5
  • 23

1 Answers1

1

If you are sure that your service is started then the reason is that service provider and your service client above see different instances of the CustomService class.

Maybe you have two bundles that export that package. Or the package is embedded into the provider or client too. Another reason might be that you retrieve the service reference before the service comes up. Do you do this in the Activator? If yes .. then this is a bad practice as you can run into timing problems. Better use a ServiceTracker or DS or blueprint.

You can check for duplicate exports using this command:

package:exports  -d
Christian Schneider
  • 19,420
  • 2
  • 39
  • 64