我尝试了一个关于通过 spring boot 使用 SOAP Web 服务的教程(入门 - 使用 SOAP Web 服务(。但是在运行 maven 构建时不会生成类。我对这个话题完全陌生,需要一些帮助来找到我的错误。这是我的绒球.xml
<?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
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.baumgarten</groupId>
<artifactId>springwsdlconsume</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- tag::wsdl[] -->
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>de.baumgarten.springwsdlconsume.hello.wsdl</generatePackage>
<schemas>
<schema>
<url>http://localhost:8080/ws/my_wsdl.wsdl</url>
</schema>
</schemas>
</configuration>
</plugin>
<!-- end::wsdl[] -->
</plugins>
</pluginManagement>
</build>
Maven 构建成功。似乎从未调用过生成目标。但这只是一个猜测。
尝试使用以下插件:-
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/wsdlFile.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
我还建议在您的pom中具有以下依赖项.xml:-
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>3.2.4</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.2.4</version>
</dependency>
尝试删除标记pluginManagement
它用于修复插件的确定版本。
在pom.xml中尝试以下代码。这将帮助您在使用多个 wdsl 时生成 java 类。如果您使用的是单个 WSDL,则从下面的代码中删除最后一个执行块。
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<executions>
<execution>
<id>number-conversion</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>com.walking.techie.number.conversion.wsdl</generatePackage>
<generateDirectory>${project.basedir}/src/main/java</generateDirectory>
<schemas>
<schema>
<url>http://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL</url>
</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>commerce-service</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>com.walking.techie.wsdl</generatePackage>
<generateDirectory>${project.basedir}/src/main/java</generateDirectory>
<schemas>
<schema>
<url>http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl</url>
</schema>
</schemas>
</configuration>
</execution>
</executions>
</plugin>
You can include the below maven dependency in the pom.xml file if you are using spring boot. It will provide WebServiceGatewaySupport class. You can extend this class in service layer and use getWebServiceTemplate().marshalSendAndReceive() method to call the wsdl service.
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
</dependency>