public interface GreetingService { void sayHello(String name); } @Component public class GreetingServiceImpl implements GreetingService { public void sayHello(String name) { System.out.println("Hello, " + name + "!"); } } public class Application { public static void main(String[] args) { FrameworkFactory frameworkFactory = new FrameworkFactory(); Framework framework = frameworkFactory.newFramework(); framework.start(); BundleContext bundleContext = framework.getBundleContext(); ServiceRegistration<GreetingService> registration = bundleContext.registerService( GreetingService.class, new GreetingServiceImpl(), null); ServiceReference<GreetingService> reference = bundleContext.getServiceReference(GreetingService.class); GreetingService service = bundleContext.getService(reference); service.sayHello("John"); framework.stop(); framework.waitForStop(0); } }


上一篇:
下一篇:
切换中文