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; }}