将非osgi与osgi包进行交互 [英] Interacting Non osgi with osgi bundles

查看:92
本文介绍了将非osgi与osgi包进行交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将struts2用于我的Web应用程序,并且我想将osgi体系结构用于服务和dao层.现在,我不想将struts2动作包装为osgi捆绑包,但希望将服务和dao层打包为捆绑包.现在有人可以告诉我我的非osgi动作如何消耗osgi包(服务和dao层).而且我想在Web容器中部署我的struts2 Web应用程序,以便在这种情况下Web容器将如何与osgi容器(在其中部署了我的服务和dao)进行交互.请帮忙.

I am using struts2 for my web application and i want to use osgi architecture for service and dao layer. Now I dont want to wrap my struts2 actions as osgi bundles but want service and dao layer to be packaged as bundles. Now can anybody tell me how my non osgi actions can consume osgi bundles(service and dao layer). And I want to deploy my struts2 web application in web container so how web container will interact with osgi container(where my service and dao is deployed) in this case . Please help .

推荐答案

您需要在Web容器和OSGi环境之间建立一个所谓的桥梁". Felix和Equinox都具有该功能,但是对我来说,Felix的实现要好得多.

You need a so called 'bridge' between your web container and your OSGi environment. Both Felix and Equinox have that capability, but for me the Felix implementation worked much better.

您基本上想做的是:

  • 向您的ServletContext添加上下文侦听器
  • 在启动ServletContext时启动OSGi,在ServletContext被销毁时将其停止.
  • 通过将ServletContext注册为服务将其传递到OSGi上下文
  • 通过将OSGi框架对象注册为属性,将其存储在ServletContext中.

因此,要从OSGi访问Web上下文:检索ServletContext服务,然后从那里开始.

So to access the web context from OSGi: Retrieve the ServletContext service, and go from there.

要从Web上下文访问OSGi:从ServletContext属性检索OSGi框架,然后从那里开始.

To access OSGi from the webcontext: Retrieve the OSGi framework from the ServletContext attribute and go from there.

检查 Felix文档,我也做了早在 GitHub

这篇关于将非osgi与osgi包进行交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆