与环境:
- 卡拉夫 3.0.1
- 春天 3.2.4
- 黑森州 4.0.33
我已经通过 CXF 公开了一项服务,现在我正试图公开与 Hessian 服务相同的服务。
没有war或web.xml,只有普通bean + pax-http,我尝试了以下方法:
<bean name="/hessian" class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service" ref="promocionalOnLineWebServiceBean"/>
<property name="serviceInterface" value="org.fideliapos.promos.webservice.PromocionalOnLineFacade"/>
</bean>
...
<bean id="hessianServlet" class="org.springframework.web.context.support.HttpRequestHandlerServlet"/>
...
<osgi:service ref="hessianServlet" interface="javax.servlet.http.HttpServlet">
<service-properties>
<entry key="alias" value="/hessian"/>
</service-properties>
</osgi:service>
这个想法是注册一个 servlet(一个 HttpRequestHandlerServlet),其目标是一个 HessianServiceExporter,但我得到一个No WebApplicationContext found: no ContextLoaderListener registered?.
我跟踪了 spring 代码,内部码头正在识别 servlet 并调用它的 init 方法:
@Override
public void init() throws ServletException {
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
this.target = wac.getBean(getServletName(), HttpRequestHandler.class);
}
这就是问题所在,因为没有 spring WebApplicationContext 并且目标属性不能被注入。
我错过了什么吗?或者不可能让它像这样工作。
作为一种解决方法,我正在考虑使用我自己的实现(setTarget 等)扩展 Servlet,但我不想这样做。
更新
在尝试创建并添加我自己的 HttpContext 之后,仍然缺少一些东西:
我实现了自己的 HttpContext:
public class HessianContext implements HttpContext{
...
}
添加了豆子
<bean id="hessianContext" class="org.fideliapos.promos.hessian.HessianContext"/>
服务:
<osgi:service id="hessianContextService" ref="hessianContext" interface="org.osgi.service.http.HttpContext">
<service-properties>
<entry key="httpContext.id" value="hessian"/> <!-- also tried with contextId-->
</service-properties>
</osgi:service>
最后是作为服务的 servlet:
<osgi:service ref="hessianServlet" interface="javax.servlet.http.HttpServlet">
<service-properties>
<entry key="alias" value="/hessian"/>
<entry key="httpContext.id" value="hessian"/> <!-- also tried with contextId-->
</service-properties>
</osgi:service>
由于init 方法正在寻找 WebApplicationContext ,因此我应该声明并显式地声明 GenericWebApplicationContext bean,但我不知道如何将这个 bean 与 OSGi 所需的 HttpContext“加入”。