在我的 Camel (2.14.0) 应用程序中,我使用 Spring Web Services 来触发 Camel 路由。该工件被构建为一个 OSGi 包并部署在 Karaf (3.0.2) 中。
对于第一个版本,我将 spring-ws 配置为通过 JVM 内部 Web 服务器org.springframework.remoting.support.SimpleHttpServerFactoryBean
来公开 Web 服务。这工作得很好。但不是很 OSGi-ish。因此,我想将org.springframework.ws.transport.http.MessageDispatcherServlet
作为服务发布到Karaf 白板扩展器,如下所示:
<bean id="pas-ws-patient-servlet" class="org.springframework.ws.transport.http.MessageDispatcherServlet">
<property name="contextConfigLocation" value="/endpoint-mapping.xml" />
</bean>
<osgi:service ref="pas-ws-patient-servlet" interface="javax.servlet.http.HttpServlet">
<service-properties>
<entry key="alias" value="/${pas.ws.patient.contextroot}" />
</service-properties>
</osgi:service>
这对于“常规” servlet 来说就像一个魅力。但是MessageDispatcherServlet
想要构建自己的WebApplicationContext
,并希望org.springframework.ws.server.EndpointMapping
在该上下文中找到类型的 bean。Camel 提供了一个EndpointMapping
必须与其 spring-ws 组件一起使用的实现。
我面临的问题是端点映射 bean 的同一个实例必须在OsgiBundleXmlApplicationContext
创建 Camel 上下文和由MessageDispatcherServlet
. 如果 myOsgiBundleXmlApplicationContext
是WebApplicationContext
. 尽管如何将 servlet 的父上下文设置为WebApplicationContext
我将 servlet 作为服务发布的“当前”上下文却让我望而却步。
WebApplicationContext
从内部实例化 aOsgiBundleXmlApplicationContext
以将其传递给 MessageDispatcherServlet 给了我一个例外:
java.lang.IllegalArgumentException: Cannot resolve ServletContextResource without ServletContext
不幸的是WebServiceMessageReceiver
( 封装了EndpointMapping
)MessageDispatcherServlet
是一个私有成员。所以我不能直接设置映射bean。
有没有办法创建上下文层次结构?或者可以以另一种方式跨上下文共享 bean 实例?