cxf、struts、spring中web.xml过滤url问题解决方案
最近项目遇到webService配置cxf过滤器时与struts冲突问题,原因是web.xml的过滤地址匹配问题,看了很多网上能找到的解决方案,在这里总结一下: cxf在spring的配置不变, [code="xml"] .........[/code] web.xml配置: cxf在web.xml配置不变 [code="xml"] CXFServlet org.apache.cxf.transport.servlet.CXFServlet 1 CXFServlet /schemas/* [/code] 方案一: 网上说的最多,但有时不一定有效的一种方法 [code="xml"] struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts2 *.action [/code] 方案二: 方法很巧妙,也是在Iteye上看的帖[url]http://www.iteye.com/topic/673231[/url] 该贴中用到的FilterDispatcher 在2.1.x以后的版本都不建议使用,所以我们可以重写StrutsPrepareAndExecuteFilter来实现过滤 [code="java"]public class StrutsFilter extends StrutsPrepareAndExecuteFilter { @Override public void init(FilterConfig filterConfig) throws ServletException { super.init(filterConfig); } @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { String url = ((HttpServletRequest)req).getRequestURI(); if (url.indexOf("schemas") < 0) { //另外一种过滤cxf方式 super.doFilter(req, res, chain); } else { chain.doFilter(req, res); } } }[/code] 这个类在我的com.chyx.web.filter包下面 web.xml [code="xml"] struts2 com.chyx.web.filter.StrutsFilter struts2 /* [/code] 方案三: 利用struts2自带的正则匹配,应该说这算是最官方的解决方案了 在struts.properties中加正则匹配 [color=darkred][b][u]struts.action.excludePattern=/schemas/.*[/u][/b][/color] web.xml [code="xml"] struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts2 /* [/code] struts的配置2处都不变
方法一很渣,忽略。 方法二,很好,我就是用的这个方法 方法三,不起作用