Interacting Non osgi with osgi bundles

二次信任 提交于 2019-12-23 20:21:58

问题


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 .


回答1:


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.

What you basically want to do is:

  • Add a context listener to your ServletContext
  • Starting OSGi when starting the ServletContext, stop it when the ServletContext gets destroyed.
  • Pass the ServletContext to the OSGi context by registering it as a service
  • Store the OSGi framework object in the ServletContext by registering it as an attribute.

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

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

Check the Felix Documentation, also I've made an example a while back on GitHub




回答2:


Most surely this will not work. Why do you think it should be a good idea to move half of your application to OSGi? Either you should move all of it or none.

You may be able to deploy the struts layer in a war file and a access the OSGi services from it. I think this is possible in Virgo and Apache Karaf. It means to enhance the war with OSGi structures. For example in Karaf you can use a wab file which is a war file with a Manifest.



来源:https://stackoverflow.com/questions/11610764/interacting-non-osgi-with-osgi-bundles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!