0

我是 OSGI 的新手,目前正在尝试使用它来创建模块化 Web 应用程序。Web 应用程序本身是使用 Vaadin 6 创建的。我在 Vaadin 网站上关注了这篇 WIKI 文章:使用 OSGI 创建模块化 Vaadin 应用程序

到目前为止我所做的步骤: - 为模块服务创建 OSGI 包(跟踪其他 osgi 模块又名插件的简单服务)并将其部署到 jboss。- 创建 vaadin 应用程序,只是一个存根。

OSGI 服务应该被注入到 Servlet 类中,例如:

@WebServlet(urlPatterns="/*")
public static class Servlet extends AbstractApplicationServlet {

@Resource(mappedName="vaadin-moduleService")
ModuleService moduleService;

@Override
protected Class<? extends Application> getApplicationClass() {
    return ModuleDemoApp.class;
}

@Override
protected Application getNewApplication(HttpServletRequest request) throws ServletException {
    return new ModuleDemoApp(moduleService);
}
}

现在的问题是——如何在此处注入此服务?目前我只是得到 NULL 指针,所以 DI 不起作用。从上面提到的文章:

Note, that the servlet has a moduleService field annotated with the 
@Resource annotation. One of the interesting features of GlassFish 3 
is that it is possible to inject references to OSGi services into all 
container managed Java beans, even though they are not actually 
running in the OSGi container themselves. Thus, in this case, GlassFish 
will find the module service we define in the previous section and inject it.

据此,Glassfish 将在内部自动完成所有魔法。有人知道如何使用 JBoss7 完成它吗?

不幸的是,对于如何在 OSGI 容器内运行的任何东西可以在其外部引用,没有找到任何好的(对于新手)解释......假设不需要将 Web 应用程序本身转换为 OSGI 包来完成我需要的东西。这是真的?

非常感谢。

4

1 回答 1

0

文档指出,JavaEE 组件可以将 BundleContext 作为@Resource. 如果可行,那么您可以通过 ServiceTracker 跟踪您的模块服务。

我在这里看到了另一个将 Vaadin 与 OSGi 一起使用的示例。

于 2013-01-23T10:14:51.373 回答