在SSM框架中部署WebService


1、引入jar

 

具體可參考網路

2、修改web.xml

 

<!--注冊一個用於接收其他工程向本工程發送的webservice請求的請求接收器-->
  <servlet>
    <servlet-name>CXFServlet</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <!--配置過濾請求地址項目名+webService+address+?wsdl-->
  <servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/TDM/*</url-pattern>
  </servlet-mapping>
web.xml

3、增加spring-cxf.xml文件

3.1 web.xml增加以下內容

 

3.2 spring-cxf.xml文件

用於定義webservice交互接口名稱

 

<?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"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
        http://cxf.apache.org/jaxws
        http://cxf.apache.org/schemas/jaxws.xsd">
    <!-- Import Apache CXF Bean Definition 引入xml並不存在 -->
    <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-->
    <bean id="hello" class="com.spring.web.webservive.cxfImpl"/>
    <!--implementor="#hello" 指向bean id="hello"-->
    <jaxws:endpoint id="helloWorld" implementor="#hello" address="/helloTest1" />
    <!--模擬客戶端 -->
    <jaxws:client id="hello1" serviceClass="com.spring.web.webservive.cxf"
address="http://localhost:8000/TDM/helloTest1" />
spring-cxf.xml

4、定義接口類與實現類

4.1定義接口類

 

package com.spring.web.webservive;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
@WebService
public interface cxf {    
    //提供一個對外公開的服務
    //@WebParam(name = "arg0") 默認值為arg0
    public String say();    
    public @WebResult(name="out1")Integer sayHello(@WebParam(name = "int1") Integer i);   
    public String sayBye(@WebParam(name = "string2") String name);
}
接口類

4.2 定義實現類

 

package com.spring.web.webservive;
import javax.jws.WebService;
@WebService(endpointInterface = "com.spring.web.webservive.cxf")
public class cxfImpl implements cxf {   
    public String say() {
        return "Hello:+Bye:";
    }   
    public Integer sayHello(Integer id) {
        return 100*id;
    }  
    public String sayBye(String name) {
        return "Bye:" + name;
    }
實現類

5、訪問及引用

localhost:8000/TDM/helloTest1?wsdl

調試使用軟件:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM