【发布时间】:2012-09-12 14:53:40
【问题描述】:
我有一个 JBoss 7.1.2 应用程序服务器启动并运行,现在我想在其中部署一个注册 servlet 的 OSGi 包。 (类似于 Hello World,但通过 servlet)
也许可以通过 WAB 将其存档,但与在 OSGi 中一样,我认为它也应该在一个简单的非 wab 包中工作。
我使用 Activator 创建了一个捆绑包,如下所示:
snip..
public void start(BundleContext bundleContext) throws Exception {
ServiceReference<?> httpServiceReference = bundleContext.getServiceReference(HttpService.class.getName());
System.out.println("ref: " + httpServiceReference);
HttpService httpService = (HttpService) context.getService(httpServiceReference);
System.out.println(httpService.getClass().getName());
try {
httpService.registerServlet("testservlet", new MyServlet() , null, null);
} catch (Exception e) {
e.printStackTrace();
}
}
部署并启动捆绑包后,httpServiceReference 为null。
我觉得这很奇怪,因为当我查看 felix Web 控制台时,实际上 is HtttpService 可用。 (来自 pax-web)
有谁知道为什么我的引用在这里可能为空? 谢谢!
【问题讨论】:
-
你能通过这个tutorial。只需将所有必要的包添加到您的 jboss 环境中。希望它可以工作,但如果没有,请给我反馈。
-
实际上,上面的代码在夜间 JBoss 7.2.x.alpha 上运行良好。 HttpService 在那个版本上被注入,所以对我来说这似乎是 7.1.x 系列中的一个错误(尝试了 7.1.1 和 7.1.2)
-
理论上它也可能是一个可见性问题。是否有多个包含 HttpService 的包的导出器?如果是这样,也许您的代码被连接到“错误的”。尝试使用 getAllServiceReferences() 来查看是否是这种情况。