Web Service(CXF)整合Web應用No services have been found

先將CXF與Spring進行整合java

web.xml文件web

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <!--指定配置文件位置、名稱-->
 <context-param>
  	<param-name>contextConfigLocation</param-name>
  	<param-value>/WEB-INF/hello-servlet.xml</param-value>
  </context-param>
  
  <listener>
  	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
   <!--CXF核心控制器-->
  <servlet>
  	<servlet-name>CXF</servlet-name>
  	<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
  </servlet>
  <servlet-mapping>
  	<servlet-name>CXF</servlet-name>
  	<url-pattern>/webservice/*</url-pattern>
  </servlet-mapping>
  
</web-app>

Spring 配置文件spring

<?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:p="http://www.springframework.org/schema/p"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://cxf.apache.org/jaxws
        http://cxf.apache.org/schemas/jaxws.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

	<import resource="classpath:/META-INF/cxf/cxf.xml"/>
	<import resource="classpath:/META-INF/cxf/cxf-servlet.xml"/>
	<context:annotation-config/>
	<bean name="helloworld" class="impl.HelloWorldws"></bean>
	<!--配置web service地址和接口實現類-->
	<jaxws:endpoint implementor="#helloworld" address="/testjava"/>
	

</beans

經過上面的配置,能夠成功訪問   
接下來改成Spring MVC
web.xml改成


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  
  <servlet>
  	<servlet-name>hello</servlet-name>
  	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  	<load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
  	<servlet-name>hello</servlet-name>
  	<url-pattern>/</url-pattern>
  </servlet-mapping>
  <servlet>
  	<servlet-name>CXF</servlet-name>
  	<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
  </servlet>
  <servlet-mapping>
  	<servlet-name>CXF</servlet-name>
  	<url-pattern>/webservice/*</url-pattern>
  </servlet-mapping>
    
</web-app>

Spring配置文件不變,結果訪問web service 時出現  No services have been found.apache

後臺:WARNING: Can't find the the request for http://localhost/CXF_Spring/webservice/testjava's Observer spring-mvc

也就是說 CXF的核心控制器沒起做用,CXF的核心控制器要依賴Spring的ContextLoaderListner,而SpringMVC用的是DiapacherServlet的配置方式。mvc

解決方案:app

拆分配置文件,spring-servlet.xml(DiapacherServlet配置方式)中配置Controller組件,beans.xml(ContextLoaderListner配置方式)中配置普通bean和CXF。url

相關文章
相關標籤/搜索