• spring boot 整合CXF创建web service


    在 spring boot 创建web service及调用 文章中使用了spring boot集成的web service starter: spring-boot-starter-web-services来创建webservice。

    有几个问题:

    1. 使用.net的动态调用连接这个webservice总是失败。

    2. WebParam注解不起作用,wsdl文件中不显示参数名称。

    于是就改成了使用cfx来做webservice 就可以解决以上问题。

    同样用之前的项目框架。只是会Server做一点修改,非常简单:

    POM文件:注意springboot 与cxf的版本兼容性。都使用最新版的话,容易出问题。

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.0.0.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.hkk</groupId>
        <artifactId>server</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>server</name>
        <description>Demo project for Spring Boot</description>
    
        <properties>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-spring-boot-starter-jaxws -->
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
                <version>3.2.4</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>

    CXF配置文件:CxfConfig:

    package com.hkk.server;
    
    import com.hkk.server.service.BillService;
    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
        BillService billService;
    
        @Bean
        public Endpoint endpoint2() {
            EndpointImpl endpoint = new EndpointImpl(bus, billService);
            endpoint.publish("/webservice");
            System.out.println("发布webService成功!");
            return endpoint;
        }
    }

    main方法去掉了启动Webservice的代码:

    @SpringBootApplication
    public class ServerApplication {
    
        public static void main(String[] args) {
    
            SpringApplication.run(ServerApplication.class, args);
    
        }
    
    }

    接口和实现的代码没有改动,访问这个webservice要注意:http://localhost:8083/services/webservice

    webservice是在cxfConfig文件中配置了。services可以通过在yml文件中修改,默认是services.

  • 相关阅读:
    ubuntu 1510
    创业者的困境
    创业者的窘境
    (转)Ubuntu 16.04下搭建Web服务器(MySQL+PHP+Apache)
    ESP8266的smartconfig过程(使用esptouch)
    Virtualbox下ubuntu识别USB设备
    红外人体检测
    树莓派跑讯飞语音识别(2麦阵列)
    R16平台中断
    语音识别下的智能家居
  • 原文地址:https://www.cnblogs.com/hankuikui/p/13042183.html
Copyright © 2020-2023  润新知