@Service
public interface GreetingService {
String getGreeting();
}
@Component
public class EnglishGreetingService implements GreetingService {
@Override
public String getGreeting() {
return "Hello!";
}
}
BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
ServiceReference<GreetingService> serviceReference = bundleContext.getServiceReference(GreetingService.class);
GreetingService greetingService = bundleContext.getService(serviceReference);
String greeting = greetingService.getGreeting();