zoukankan      html  css  js  c++  java
  • SpringBoot使用webservice

    Pom.xml

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.9.RELEASE</version>
            <relativePath/>
        </parent>
    
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-thymeleaf</artifactId>
            </dependency>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
                <version>3.1.12</version>
            </dependency>
            <dependency>
                <groupId>commons-lang</groupId>
                <artifactId>commons-lang</artifactId>
                <version>2.6</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>1.2.30</version>
            </dependency>
        </dependencies>

    服务接口

    import javax.jws.WebMethod;
    import javax.jws.WebParam;
    import javax.jws.WebService;
    
    /**
     * 网吧web services 接口
     * @author xiaojf 2017/7/24 21:35
     */
    @WebService(targetNamespace = "http://service.netbar.temple.xiaojf.cn")// 命名空间,一般是接口的包名倒序
    public interface NetbarServices {
        @WebMethod
        String sayHello(@WebParam(name = "userName") String name);
    }

    服务实现

    import org.springframework.stereotype.Component;
    
    import javax.jws.WebService;
    
    /**
     *  网吧web services 接口实现
     * @author xiaojf 2017/7/24 21:38
     */
    @WebService(serviceName = "NetbarServices"//服务名
            ,targetNamespace = "http://service.netbar.temple.xiaojf.cn"//报名倒叙,并且和接口定义保持一致
            ,endpointInterface = "cn.xiaojf.temple.netbar.service.NetbarServices")//包名
    @Component
    public class NetbarServicesImpl implements NetbarServices {
        @Override
        public String sayHello(String name) {
            return "hello , "+ name;
        }
    }

    发布服务

    import org.apache.cxf.Bus;
    import org.apache.cxf.jaxws.EndpointImpl;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    
    import javax.xml.ws.Endpoint;
    
    @Configuration
    public class CxfConfig {
        @Autowired
        private Bus bus;
        @Autowired
        private NetbarServices netbarServices;
    
        @Bean
        public Endpoint endpoint() {
            EndpointImpl endpoint = new EndpointImpl(bus,netbarServices);
            endpoint.publish("/testservice");//接口发布在 /test 目录下
            return endpoint;
        }
    }

    验证

    http://localhost:8002/services/mytestservice?wsdl

    创建成功以后webservice是在 /services/目录下

    如http://localhost:8080/services/mdmws?wsdl

  • 相关阅读:
    Dev 控件笔记1 repositoryItemLookUpEdit 控件
    装饰账务管理
    Tiptop ERP 采购运费一键分摊
    笔记:两数互相交换,不使用第三方变量
    .net core3.0 webapi搭建(一)
    【笔记】冒泡排序
    Mysql 几种常见的插入 Insert into,Replace Into,Insert ignore
    【转】IEnumerable接口的一个简单示例
    [转]从实例谈OOP、工厂模式和重构
    浅谈C#委托的用法-delegate[转]
  • 原文地址:https://www.cnblogs.com/liuxm2017/p/9810805.html
Copyright © 2011-2022 走看看