与环境有关:
我已经通过CXF公开了一个服务,现在我试图公开与Hessian服务相同的服务。
没有war或web.xml,只有普通bean+pax,我尝试了以下方法:
<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注册?。
我已经跟踪了spring代码,内部jetty正在识别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‘连接’。
发布于 2015-03-10 07:40:04
看起来您需要将servlet添加到用于servlet的WebApplicationContext中。现在您使用Pax的DefaultHttpContext。在您的例子中,您需要注册一个自定义的HttpContext,它知道Spring的内容,这样这个HttpContext就能够提取这些信息。为此,您需要将您的自定义HttpContext注册为服务并在Servlet中引用它,使用蓝图(类似于spring)的完整示例可以找到这里
以下是本报告的摘录:
<service id="forbiddenCtxtService" ref="forbiddenContext" interface="org.osgi.service.http.HttpContext">
<service-properties>
<entry key="httpContext.id" value="forbidden"/>
</service-properties>
</service>重要的部分是httpContext.id
<bean id="forbiddenServlet" class="org.ops4j.pax.web.extender.samples.whiteboard.internal.WhiteboardServlet">
<argument type="java.lang.String" value="/forbidden"/>
</bean>
<service id="forbiddenServletService" ref="forbiddenServlet" interface="javax.servlet.Servlet">
<service-properties>
<entry key="alias" value="/forbidden"/>
<entry key="httpContext.id" value="forbidden"/>
</service-properties>
</service>在这里,注册的Servlet确实有相应的httpContext.id的配置,这将这个Servlet绑定到以前注册的HttpContext。
https://stackoverflow.com/questions/28942887
复制相似问题