SpringBoot WebService IDEA版本 客户端调用(postman调用)

webservice是什么

网上的解释很多,其实就是跨语言和操作系统的的远程调用技术。比如亚马逊,可以将自己的服务以webservice的服务形式暴露出来,我们就可以通过web调用这些,无论我们使用的语言是java还是c,这也是SOA应用一种表现形式。

注意点讲在前面

1.命名空间(nameSpase)

.xsd文件targetNamespace == Endpoint的NAMESPACE_URI

1. 新建springboot工程

新建一个简单的springboot

2.添加依赖

主要依赖

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-ws</artifactId>
      <version>1.4.7.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>wsdl4j</groupId>
      <artifactId>wsdl4j</artifactId>
    </dependency>
  </dependencies>

3.编写schema文件

spring-ws的发布,都是以一个schema文件(xsd)定义开始的,它描述了web service的参数以及返回的数据。

直接修改官方示例给出的countries.xsd:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:tns="http://www.dexcoder.com/ws"
  targetNamespace="换成你的命名空间" elementFormDefault="qualified">


  <xs:element name="getCountryRequest">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="name" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="getCountryResponse">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="country" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

4.添加maven的jaxb2插件来生成代码

jaxb2插件可以根据描述的xsd文件来帮我们生成相应的ws代码

  <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxb2-maven-plugin</artifactId>
        <version>1.6</version>
        <executions>
          <execution>
            <id>xjc</id>
            <goals>
              <goal>xjc</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <schemaDirectory>${
   project.basedir}/src/main/resources</schemaDirectory>
          <outputDirectory>${
   project.basedir}/src/main/java</outputDirectory>

你可能感兴趣的:(Spring,SpringBoot,WebService,SpringBoot,WebService,WebService,springboot,ws,postman,调用WebSerice,postman,webservice)