public interface HelloService { String sayHello(String name); } @Component public class HelloServiceImpl implements HelloService { @Override public String sayHello(String name) { return "Hello, " + name; } } @Component public class HttpServiceActivator implements BundleActivator { private ServiceRegistration<?> serviceRegistration; @Override public void start(BundleContext bundleContext) throws Exception { Dictionary<String, String> serviceProps = new Hashtable<>(); serviceProps.put("osgi.jaxrs.resource", "/hello"); serviceRegistration = bundleContext.registerService( HelloService.class.getName(), new HelloServiceImpl(), serviceProps); } @Override public void stop(BundleContext bundleContext) throws Exception { serviceRegistration.unregister(); } }


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