java.lang.NoClassDefFoundError:javax/xml/soap/SOAPException

gra*_*gos 14 java xml spring soap spring-ws

我使用Spring创建了一个Web服务.在我的嵌入式tomcat服务器上运行它时工作正常.但是,当我将其打包为JAR文件并使用java -jar命令运行它时,我收到此异常.

我的服务发送一个简单的soap请求,服务器响应是:

 "exception": "java.lang.NoClassDefFoundError",
    "message": "javax/xml/soap/SOAPException",
Run Code Online (Sandbox Code Playgroud)

这是我在邮差中得到的回应.

任何我可以寻找问题的想法.

小智 17

是的,在 Java 11 中 java.xml.soap 被完全删除了。 java.lang.NoClassDefFoundError: javax/xml/soap/SOAPException可以通过添加以下依赖项来删除。

<dependency>
    <groupId>jakarta.xml.soap</groupId>
    <artifactId>jakarta.xml.soap-api</artifactId>
    <version>2.0.0-RC3</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

但是稍后,您会遇到,javax.xml.soap.SOAPException: Unable to create SAAJ meta-factory: Provider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found。这可以通过添加以下依赖项来解决。

<dependency>
    <groupId>com.sun.xml.messaging.saaj</groupId>
    <artifactId>saaj-impl</artifactId>
    <version>1.5.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你!

  • 我可以确认 Java 11 缺少实现:`com.sun.xml.messaging.saaj:saaj-impl`。我们不需要 `soap-api` 定义。 (2认同)

use*_*582 15

JavaSE 8包含包java.xml.soap.
JavaSE 9将包移动javax.xml.soap到模块java.xml.ws.
与JEE(如共享的模块java.xml.ws)包括在JavaSE的9,但
- 弃用用于去除从JavaSE中的未来版本,以及
- 不是默认模块路径上.

一个快速的解决方法是
- 使用JRE 8运行jar:$MY_JRE8_HOME/bin/java -jar my.jar
- 为JRE 9添加模块:java --add-modules java.xml.ws -jar my.jar

从长远来看,使用类似模块的JavaSE项目java.xml.ws必须像其他库一样明确地包含模块.

请参阅/sf/answers/3245136821/
请参阅JDK 9迁移指南:与JEE共享的模块默认情况下未解析

(在https://spring.io/guides/gs/producing-web-service/上重现了NoClassDefError和压缩SOAP Web服务项目的变通方法)


小智 13

添加以下依赖项,它应该可以工作

<dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-core</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.messaging.saaj</groupId>
        <artifactId>saaj-impl</artifactId>
        <version>1.5.0</version>
    </dependency>
    <dependency>
        <groupId>javax.xml.ws</groupId>
        <artifactId>jaxws-api</artifactId>
        <version>2.2.6</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

运行一段代码请参考以下链接(SpringBootSOAPWS + Java10) Github-SpringBoot Soap Server Github-SpringBoot Soap Client


Jit*_*med 7

在pom文件中添加以下内容解决了该问题

<!-- https://mvnrepository.com/artifact/javax.xml.soap/javax.xml.soap-api -->
<dependency>
    <groupId>javax.xml.soap</groupId>
    <artifactId>javax.xml.soap-api</artifactId>
    <version>1.4.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)


pri*_*sar 6

添加此依赖项将解决该问题。

    <dependency>
        <groupId>com.sun.xml.messaging.saaj</groupId>
        <artifactId>saaj-impl</artifactId>
        <version>1.5.0</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)