java - springmvc整合cxf發佈webservice

1.jar包已上傳百度雲盤,在jar包目錄下java

2.web.xml配置web

<web-appspring

  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"apache

  xmlns="http://java.sun.com/xml/ns/javaee"spring-mvc

  xsi:schemaLocation="mvc

    http://java.sun.com/xml/ns/javaeeapp

    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">url

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/application/applicationContext-*.xml</param-value>
  </context-param>
  <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <servlet>
    <servlet-name>CXFServlet</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>spa

2.WEB-INF新建springmvc-servlet.xml  (因爲web.xml沒有配置該xml路徑和地址,因此名字不能改,位置放到這裏就行)3d

  配置內容以下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.1.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/beans/spring-beans-4.1.xsd ">

  <!-- 啓動註解驅動-->
  <mvc:annotation-driven/>
  <!-- 啓動包掃描功能,你的代碼-->
  <context:component-scan base-package="com.cxf.*" />
</beans>

3.src目錄,包名必定要com.cxf.*,由於springmvc-servlet.xml配置自動掃描的這個。

com.cxf.service.imp就是你要發佈的webservice。

先說一下com.cxf.service實現類代碼注意點:

上面註解不要漏就好了;

 

com.cxf.service.imp代碼注意點:

第一個紅線是接口路徑。

第二個紅線隨便取名,可是不能不取名。發佈後,在wsdl上會看看這個。

4.WEB-INF下新建目錄和文件   application/applicationContext-cxf.xml,文件名和路徑就是這個,不許改。由於web.xml這樣配置的。哈哈哈。(其實applicationContext-cxf.xml的名字能夠小改,本身理解吧)

內容:

<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-4.1.xsd
  http://cxf.apache.org/jaxws
  http://cxf.apache.org/schemas/jaxws.xsd">

  <!-- cxf3.0及以上版本不須要再手工引入
  <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" /> -->

  <!-- webservice服務l,implementor對應的是實現類,address,是訪問的名字-->
  <jaxws:endpoint id="HelloWorld" implementor="com.cxf.service.imp.SB_SOA_SOA_ImportOrgBpelInfoSrv" address="/org" />

  <!--啓動後,訪問:http://localhost:8080/ws/org?wsdl 會出現xml那就ok了。ws是我項目名字-->
  <!--<jaxws:endpoint id="HelloWorld2" implementor="com.cxf.service.imp.SB_SOA_SOA_ImportEmpBpelInfoSrv" address="/emp" />-->

  <!--啓動後,訪問:http://localhost:8080/ws/emp?wsdl 會出現xml那就ok了。ws是我項目名字--></beans>

相關文章
相關標籤/搜索