最近项目遇到webService配置cxf过滤器时与struts冲突问题,原因是web.xml的过滤地址匹配问题,看了很多网上能找到的解决方案,在这里总结一下:
cxf在spring的配置不变,
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
.........
web.xml配置:
cxf在web.xml配置不变
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/schemas/*</url-pattern>
</servlet-mapping>
方案一:
网上说的最多,但有时不一定有效的一种方法
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern><!--此处把/* 改成 *.action-->
</filter-mapping>
方案二:
方法很巧妙,也是在Iteye上看的帖
http://www.iteye.com/topic/673231
该贴中用到的FilterDispatcher 在2.1.x以后的版本都不建议使用,所以我们可以重写StrutsPrepareAndExecuteFilter来实现过滤
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);
}
}
}
这个类在我的com.chyx.web.filter包下面
web.xml
<filter>
<filter-name>struts2</filter-name>
<filter-class>com.chyx.web.filter.StrutsFilter</filter-class>
</filter><!--此处把StrutsPrepareAndExecuteFilter改成了重写的StrutsFilter-->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern><!-- 此处不变 -->
</filter-mapping>
方案三:
利用struts2自带的正则匹配,应该说这算是最官方的解决方案了
在struts.properties中加正则匹配
struts.action.excludePattern=/schemas/.*
web.xml
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
struts的配置2处都不变
分享到:
相关推荐
<import resource="classpath:META-INF/cxf/cxf.xml"/> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/> <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
cxf spring maven 实例 webservice
org.apache.cxf.spring.remoting.Jsr181HandlerMapping.jar
CXF+spring+struts实现WebService
PacktPub.Apache.CXF.Web.Service.Development.Dec.2009.rar
struts2.3.24升级2.5.26一些jar包和注意事项
webservice cxf spring jar包大全,下载,超好用的
一个文件:cxf-core-3.1.3.jar cxf-core-3.1.3.jar cxf-core-3.1.3.jar
cxf spring server client demo.rar soap webservice
spring 整合cxf 服务端demo,包含相关jar包
cxf+spring开发所必备的jar包压缩包
2.web工程的web.xml中配置CXFServlet <!-- 设置Spring容器加载配置文件路径 --> <param-name>contextConfigLocation <param-value>classpath*:applicationContext-server.xml <listener-class>org....
cxf-core-3.1.16版本jar包,用于java开发使用
spring-web-3.0.7.RELEASE.jar stax2-api-3.1.1.jar velocity-1.7.jar woodstox-core-asl-4.1.4.jar wsdl4j-1.6.2.jar wss4j-1.6.7.jar xalan-2.7.1.jar xml-resolver-1.2.jar xmlbeans-2.5.0.jar xmlschema-core-...
apache-cxf-2.7.18-src.zip
废话不多说,直接上代码,配置文件
apache-cxf-2.6.2.tar.gz CXF及其依赖包
利用CXF和Spring结合搭建的SOA例子,内容包含服务端配置和一个客户端测试配置,服务器端服务配置在beans.xml中,web.xml文件需要修改;客户端测试配置地址是demo.spring.client下的client-beans.xml,测试类为...
Struts2升级到2.5.30,问题解决及过程记录, 文章详见:https://blog.csdn.net/sinat_36743893/article/details/124582101