• spring 4.0下集成webservice


    该教程使用的项目可参见:

    Intellij Idea下搭建基于Spring+SpringMvc+MyBatis的WebApi接口架构

    具体源码请参见GitHub:

    https://github.com/chenyangsocool/ssm.git

    1.在maven的pom文件中添加cxf版本属性信息:

    <cxf.version>3.0.8</cxf.version>

    添加如下cxf的jar包:

    <dependency>  
                <groupId>org.apache.cxf</groupId>  
                <artifactId>cxf-rt-frontend-jaxws</artifactId>  
                <version>${cxf.version}</version>  
            </dependency>  
            <dependency>  
                <groupId>org.apache.cxf</groupId>  
                <artifactId>cxf-rt-transports-http</artifactId>  
                <version>${cxf.version}</version>  
            </dependency>  
            <dependency>  
                <groupId>org.apache.cxf</groupId>  
                <artifactId>cxf-rt-transports-http-jetty</artifactId>  
                <version>${cxf.version}</version>  
            </dependency>  
            <dependency>  
                <groupId>org.apache.geronimo.specs</groupId>  
                <artifactId>geronimo-ws-metadata_2.0_spec</artifactId>  
                <version>1.1.3</version>  
            </dependency>

    2.在ITestService上添加@WebService标签,最后文件如下:

    package com.chenyangsocool.ssm.service;
    
    import com.chenyangsocool.ssm.model.Test;
    
    import javax.jws.WebService;
    
    @WebService
    public interface ITestService {
        public Test getModelById(int id);
    }

    3.在resources目录下新建spring-cxf.xml文件,内容如下:

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- START SNIPPET: beans -->
    <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.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-servlet.xml"/>
        <jaxws:endpoint id="TestService" implementor="com.chenyangsocool.ssm.service.impl.TestServiceImpl" address="/TestService"/>
    </beans>

    4.在web.xml的<context-param>中添加spring-cxf.xml,最后如下:

        <param-value>
          classpath:spring-mybatis.xml
          classpath:spring-cxf.xml
        </param-value>

    再添加:

      <servlet>
        <description>Apache CXF Endpoint</description>
        <display-name>cxf</display-name>
        <servlet-name>cxf</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>cxf</servlet-name>
        <url-pattern>/webservice/*</url-pattern>
      </servlet-mapping>

    OK,到此结束,运行你的项目,输入:http://localhost:8080/ssm/webservice

    里面就有你添加的服务:TestService:

    http://localhost:8080/ssm/webservice/TestService?wsdl

    本项目GitHub地址:https://github.com/chenyangsocool/ssm.git

    参考(这一篇基本上是照搬了,感谢原作者):

    spring4.1.6+cxf3.0.8的简单WebService案例(maven工程)

  • 相关阅读:
    <爬虫实例> 8684公交网-太原公交线路信息
    <爬虫> requests模块
    爬虫四 selenium + phantomjs & Headless Chrome
    爬虫三 bs4&xpath&jsonpath
    爬虫二 cookie&正则
    爬虫一 发请求&定制请求&异常处理&配置代理
    抽屉页面设计
    HTML标签及其属性
    Python之路 day3 高阶函数
    Python之路 day3 递归函数
  • 原文地址:https://www.cnblogs.com/chenyangsocool/p/8575436.html
Copyright © 2020-2023  润新知