首页  编辑  

SpringBoot 3.x下根据wsdl文件进行WebService调用

Tags: /Java/   Date Created:
SpringBoot, Web Service, Soap。
现有 WSDL文件,原来提供了一个package可以配合 org.glassfish.metro/webservices-rt 和 webservices-api 使用,但是更新到SpringBoot后,且由于公司政策,不允许使用glashfish 这两个包,因此只能另外想办法解决。

1. 首先,引入:
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
    <version>4.0.0</version>
</dependency>
<dependency>
    <groupId>jakarta.xml.bind</groupId>
    <artifactId>jakarta.xml.bind-api</artifactId>
    <version>4.0.4</version>
</dependency>
2. 在 POM.xml 中,添加:
<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.5.5</version>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <wsdlOptions>
                            <wsdlOption>
                                <wsdl>${project.basedir}/src/main/resources/META-INF/wsdls/BDSServiceWebSPort.wsdl
                                </wsdl>
                                <extraargs>
                                    <extraarg>-wsdlLocation</extraarg>
                                    <extraarg>classpath:META-INF/wsdls/BDSServiceWebSPort.wsdl/</extraarg>
                                </extraargs>
                            </wsdlOption>
                        </wsdlOptions>
                    </configuration>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
3. 运行 mvn generate-source 生成 Web Service 类
4. 修改生成的 java 类,把其中 javax.xml.* 的类的引入,改为 jakarta.xml 的引入即可。
5. 加上最后缺少的依赖:
<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
</dependency>