struts2与cxf配置.优化

来源:互联网 发布:windows ce刷成安卓 编辑:程序博客网 时间:2024/06/15 05:09

内容很简单.我之前配置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

 

我建议用第三种.

 

原创粉丝点击