public class HelloServiceImpl implements HelloService {
public void sayHello() {
System.out.println("Hello, OSGi!");
}
}
public class HelloServiceConsumer {
private HelloService helloService;
public void bindHelloService(HelloService helloService) {
this.helloService = helloService;
}
public void sayHello() {
helloService.sayHello();
}
}
HelloService helloService = new HelloServiceImpl();
ServiceRegistration<HelloService> serviceRegistration = bundleContext.registerService(
HelloService.class, helloService, null);
ServiceReference<HelloService> serviceReference = bundleContext.getServiceReference(HelloService.class);
HelloService helloService = bundleContext.getService(serviceReference);
helloService.sayHello();