zoukankan      html  css  js  c++  java
  • spring4.0j集成webService

    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工程)

  • 相关阅读:
    数学图形(2.10)一种绕在球上的线圈
    数学图形(2.9) Capareda曲线
    数学图形(2.8)Viviani曲线
    数学图形(2.7)sphere sine wave
    数学图形(2.5)Loxodrome曲线
    数学图形(2.6)Satellit curve
    数学图形(2.4)网球上的曲线
    数学图形(2.3)绕在圆环上的曲线
    数学图形(2.2)N叶结
    数学图形(2.1)三叶结
  • 原文地址:https://www.cnblogs.com/liyiren/p/10592460.html
Copyright © 2011-2022 走看看