SpringBoot无法从WSDL生成类

3

我尝试了一个关于通过Spring Boot消费SOAP Web服务的教程(入门指南 - 消费SOAP Web服务)。但是在运行Maven构建时没有生成类。我对这个主题完全不熟悉,需要一些帮助找到我的错误。这是我的pom.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构建成功。似乎没有调用生成目标。但这只是一个猜测。


请检查 Web 服务 URL http://www.webservicex.com/stockquote.asmx?WSDL,该地址不存在。我希望您能提供一个返回 WSDL 的 Web 服务 URL,这样就可以正常工作了。 - soufrk
谢谢您的评论,但是正如您所看到的,我的pom文件中有另一个URL指向一个现有的WSDL ;) - Raistlin
我尝试使用这个网络服务,而且它有效。 - soufrk
奇怪,仍然没有类生成。 - Raistlin
4个回答

7

尝试使用以下插件:-

<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>

2

尝试移除标签pluginManagement

它用于固定插件的特定版本。


工作正常,谢谢。 - Mohammed Salah

0

在 pom.xml 文件中尝试以下代码,这将帮助您在使用多个 wdsl 时生成 java 类。如果您只使用单个 WSDL,则从下面的代码中删除最后一个 execution 块。

 <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>

0
<plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <version>0.15.3</version>
        <executions>
            <execution>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <args>
                        <arg>-wsdl</arg> <!-- Enable WSDL support -->
                    </args>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <generatePackage>com.exmple.services.wsdl</generatePackage>
                    <generateDirectory>${project.basedir}/src/main/java</generateDirectory>
                    <schemaDirectory>${project.basedir}/src/main/resources/wsdl</schemaDirectory>
                    <schemaIncludes>
                        <include>*.wsdl</include>
                    </schemaIncludes>
                </configuration>
            </execution>
        </executions>
    </plugin>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接