首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 服务器 > Apache >

Apache xml-rpc与spring的调整

2012-06-29 
Apache xml-rpc与spring的整合  之前在项目中使用了Apache xml-rpc,遇到了一个麻烦的问题。spring没有提供

Apache xml-rpc与spring的整合
  之前在项目中使用了Apache xml-rpc,遇到了一个麻烦的问题。spring没有提供对xml-rpc的支持,在处理webservice请求的时候,没有办法使用spring容器中管理的各种各样的bean对象。显然,这是不能接受的。

  使用Apache xml-rpc,一般只需要在web.xml中定义一个servlet (XmlRpcServlet), 再实现用于处理webservice请求的组件类就可以了。
  比如定义一个Servlet:

public class CustomXmlRpcServlet extends XmlRpcServlet{    private static final long serialVersionUID = 8615627610262194L;    protected static ApplicationContext ctx = null;    public CustomXmlRpcServlet()    {        super();    }    public void init()    {        if (ctx == null)        {            ctx = WebApplicationContextUtils                    .getRequiredWebApplicationContext(this.getServletContext());        }    }    protected XmlRpcHandlerMapping newXmlRpcHandlerMapping()            throws XmlRpcException    {        PropertyHandlerMapping mapping = new PropertyHandlerMapping();                CustomWebServiceHandler service = (CustomWebServiceHandler) ctx.getBean("customWebServiceHandler");                mapping.setRequestProcessorFactoryFactory(new CustomRequestProcessorFactoryFactory(service));        mapping.addHandler("CustomWebServiceHandler", CustomWebServiceHandler.class);        return mapping;    }}

  这样扩展以后,之前提到的XmlRpcServlet.properties文件也不再需要了。

热点排行