zoukankan      html  css  js  c++  java
  • 在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

    调试使用软件:

    我驰骋天下,守你盛世繁华
  • 相关阅读:
    iOS中Zbar二维码扫描的使用
    SOJ 1135. 飞跃原野
    SOJ 1048.Inverso
    SOJ 1219. 新红黑树
    SOJ 1171. The Game of Efil
    SOJ 1180. Pasting Strings
    1215. 脱离地牢
    1317. Sudoku
    SOJ 1119. Factstone Benchmark
    soj 1099. Packing Passengers
  • 原文地址:https://www.cnblogs.com/lotuses/p/11357737.html
Copyright © 2011-2022 走看看