struts2与cxf配置.优化

本文介绍了一个关于在Spring、Hibernate、Struts2等技术栈中集成CXF遇到404错误的问题及解决方案。作者通过调整配置,解决了CXF服务无法正常映射的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

内容很简单.我之前配置cxf总是出来404我是看着demo做的啊,怎么会呢.

 

我就从项目中找啊找.我的项目是Spring2.5.6+Hibernate3.3.1+Struts2.1.8.1+urlrewrite3.2+cxf2.3.5

 

这个是我的web.xml

通常的都是这么配置的,但是你其他的写完了之后呢就会发现总是出现404错误.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:cngrideye-config.xml</param-value>
	</context-param>
	<listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    
    <listener>  
    	<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>  
  	</listener>
  	
    <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>/services1/*</url-pattern>
	</servlet-mapping>
	<!-- 静态URL
	 要放在struts2过滤器前面.
	-->
	<filter>   
	    <filter-name>UrlRewriteFilter</filter-name>   
	    <filter-class>   
	        org.tuckey.web.filters.urlrewrite.UrlRewriteFilter   
	    </filter-class>   
	    <init-param>   
	        <param-name>logLevel</param-name>   
	        <param-value>WARN</param-value>   
	    </init-param>   
	</filter>   
	<filter-mapping>   
	    <filter-name>UrlRewriteFilter</filter-name>   
	    <url-pattern>/*</url-pattern>
	</filter-mapping>  
	 
	<filter>
		<filter-name>struts2</filter-name>
		<!-- 
		<filter-class>
			org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
		 -->
		<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
		
	</filter>
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
		<dispatcher>REQUEST</dispatcher>     
        <dispatcher>FORWARD</dispatcher>     
       	<dispatcher>INCLUDE</dispatcher>    
		<!-- 
		<url-pattern>*.action</url-pattern>
		<url-pattern>*.jsp</url-pattern> 
		-->
	</filter-mapping>
	
	
	
	
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
	<login-config>
		<auth-method>BASIC</auth-method>
	</login-config>
 
</web-app>


 

我的cxf配置如下.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
	xmlns:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.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" />
	<jaxws:endpoint id="Hello" implementor="cn.aozer.armsweb.webservice.impl.DataImpl"
		address="/HelloWorld" />


</beans>

 

 

404如下:

 


 

这时候就有多种解决方法了.

第一就是:把struts2匹配原则改一下改成*.action

第二就是:把cxf匹配改一下,改成*.ws

第三就是:吧bean里面修改改成helloword.ws

 

我建议用第三种.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值