I am not an expoert, but I would like to  do the same spring application.

You could publish your Beans(Services) to Karaf using Osgi context (Osgi
Service), You can expose the OSGI Services as Spring Bean (Spring Services)
in your SpringBoot Configuration getting from OSGI Context.

publish your beans


// Your Consumer and Producer Services (Osgi Jars) must get the Interfaces
from a API JAR, dont include the class theirs  osgi jars.
api.jar (all services interfaces)
service-impl.jar (services implementations who expose the osgi service)
service-consumer.jar (get the service implementation from osgi)

// GET from your Activator

BundleContext ctx


@Bean Service createService() { Service service = new
ServiceImpl();ctx.registerService(Service.class, service, new
Hashtable<String, String>()); return service}

Getting Service to use in Spring

@Configuration
OsgiServiceProvider

// GET from your Activator

private static BundleContext bundleContext;

@Bean Service injectService() { // GET the from your BundleContext
return (Service)(bundle.getService()) }

ServiceReference ref =
bundleContext.getServiceReference(Service.class.getName());
  Service service = (Service) bundleContext.getService(ref);

return service;


After, *you need to register listeners about services/bundles* was
*undeployed*, or was *deployed* (changes of the services
instances)..You will be need a wrapper of your service in your
Consumer.

public class ServiceWrapper implements Service

Service target; // to call the real service instance, because could be
deployed and undeployed

Best Regards

Reply via email to