SpringBoot结合cxf自动生成webservice客户端代码插件
一、创建Maven项目
二、引入CXF的插件依赖
<?xml version="1.0" encoding="UTF-8"?>
test
test
0.0.1-SNAPSHOT
4.0.0
<artifactId>type-generator</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cxf.version>3.2.6</cxf.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<encoding>UTF-8</encoding>
<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
<!--<sourceRoot>src/main/java</sourceRoot>-->
<defaultOptions>
<extraargs>
<extraarg>-impl</extraarg>
<extraarg>-verbose</extraarg>
<extraarg>-validate</extraarg>
<extraarg>-client</extraarg>
</extraargs>
</defaultOptions>
<wsdlOptions>
<wsdlOption>
<wsdl>http://0.0.0.0:8080/services/getWeatherService?wsdl</wsdl>
<!--<wsdl>D:\code\Demo\src/main/resources/HVSService.wsdl</wsdl>-->
<extraargs>
<extraarg>-p</extraarg>
<extraarg>xxx.xxx.xxx.xxx.xxx</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
注:如果有现成的WSDL文件,可以将WSDL文件存放至项目指定目录,并配置好路径;
D:\code\Demo\src/main/resources/HVSService.wsdl
反之若是没有,可以通过服务url获取:
// 此为个人样板示例,仅供参考
localhost:8080/Service/HVSService.wsdl
三、Maven编译
最后在idea的maven终端编译即可 键入编译命令:mvn generate-sources