我添加了以下捆绑包,可以将战争(Web 应用程序)部署到 OSGi 框架中。我使用“Apache Felix 可分发二进制文件”:
32|Active | 20|OPS4J Pax Logging - API (1.7.0)
33|Active | 20|OPS4J Pax Logging - Service (1.7.1.SNAPSHOT)
34|Active | 20|OPS4J Pax Url - mvn: (1.3.5)
35|Active | 20|OPS4J Pax Url - war (1.3.5)
36|Active | 20|OPS4J Pax Url - wrap: (1.3.5)
37|Active | 20|OPS4J Pax Web - API (1.1.12)
38|Active | 20|OPS4J Pax Web - FileInstall Deployer (1.1.12)
39|Active | 20|OPS4J Pax Web - Extender - WAR (1.1.12)
40|Active | 20|OPS4J Pax Web - Extender - Whiteboard (1.1.12)
41|Active | 20|OPS4J Pax Web - Jetty Bundle (1.1.12)
42|Active | 20|OPS4J Pax Web - Jsp Support (1.1.12)
43|Active | 20|OPS4J Pax Web - Runtime (1.1.12)
44|Active | 20|OPS4J Pax Web - Service SPI (1.1.12)
因此,我使用了一个简单的 struts 2 应用程序(Hello world)进行测试,我创建了战争,然后将其放在“文件安装”目录中,它变得活跃,我可以看到我的欢迎页面。
在此之后,我尝试检索 BundleContext 以使用战争中注册的服务,我添加了:
BundleContext ctx = (BundleContext) ServletActionContext.getServletContext().getAttribute("osgi-bundlecontext");
但是,我发现了异常:
“java.lang.ClassCastException:org.apache.felix.framework.BundleContextImpl 无法转换为 org.osgi.framework.BundleContext”
可能是什么问题?
谢谢