【发布时间】:2013-04-07 20:04:34
【问题描述】:
在 OSGi 4 容器中创建基本 JAX-RS 环境的最简单方法是什么,无需求助于 Apache CXF 等重量级解决方案。
虽然在我看来,用HttpService 注册一个 Jersey 容器 servlet 应该可以解决问题,但我无法拼凑出一个仅包含几个包的集合。
这就是我的bundle Activator的本质,其中Resources类实现了Application接口来解析哪些类有JAX-RS注解:
public void start(BundleContext context) throws Exception {
// Find the HttpService
ServiceReference ref = context.getServiceReference(HttpService.class.getName());
HttpService service = (HttpService) context.getService(ref);
// Register a Jersey container
ServletContainer servlet = new ServletContainer(new Resources());
service.registerServlet("/services", servlet, null, null);
}
【问题讨论】: