我使用Spring创建了一个Web服务。在我的嵌入式tomcat服务器上运行它时工作正常。但是,当我将其打包为JAR文件并使用java -jar
命令运行时,我收到此异常。
我的服务发送一个简单的soap请求,服务器响应是:
"exception": "java.lang.NoClassDefFoundError",
"message": "javax/xml/soap/SOAPException",
这是我在Postman中得到的回应。
我可以找到问题的任何想法。
答案 0 :(得分:10)
JavaSE 8包含包java.xml.soap
JavaSE 9将包javax.xml.soap
移动到模块java.xml.ws
与JEE共享的模块(如java.xml.ws
)包含在JavaSE 9中,但是为了
- deprecated用于从未来版本的JavaSE中删除,以及
- not on the default module path。
快速解决方法是要么
- 使用JRE 8运行jar:$MY_JRE8_HOME/bin/java -jar my.jar
或
- 为JRE 9添加模块:java --add-modules java.xml.ws -jar my.jar
从长远来看,使用像java.xml.ws
这样的模块的JavaSE项目必须像其他库一样明确地包含该模块。
见https://stackoverflow.com/a/46359097
见JDK 9 Migration Guide: Modules Shared with JEE Not Resolved by Default
(转载NoClassDefError并在https://spring.io/guides/gs/producing-web-service/处使用压缩的SOAP Web服务项目进行解决方法)
答案 1 :(得分:9)
是的,在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>
但是稍后,您将遇到 javax.xml.soap.SOAPException:无法创建SAAJ元工厂:Provider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl未找到。 这可以通过添加以下依赖项来解决。
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.1</version>
</dependency>
希望,有帮助!
答案 2 :(得分:7)
答案 3 :(得分:4)
在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>
答案 4 :(得分:2)
添加此依赖性将解决此问题。
[HttpGet]
public ActionResult Politicians()
{
var publishInfo = TempData["Info"];
var sessionInfo = Session["Info"];
return View(new Config());
}
[HttpPost]
public ActionResult PublishConfig()
{
TempData["Info"] = "publish error";
Session["Info"] = "session info";
return RedirectToAction("Politicians", "Parliament", new { area = "Admin" });
}
答案 5 :(得分:0)
添加以下依赖项,然后它应该可以工作
<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>
请参考以下链接以获取运行中的代码(SpringBootSOAPWS + Java10) Github- SpringBoot Soap Server Github- SpringBoot Soap Client
答案 6 :(得分:0)
缺少 JAX-WS 依赖库“jaxws-api.jar”。 试试:
compile group: 'javax.xml.ws', name: 'jaxws-api', version: '2.3.1'
- 用于 gradle 或:
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
答案 7 :(得分:-3)
我认为问题是缺少JAX-WS依赖库“jaxws-api.jar”。
请点击此链接http://jax-ws.java.net/。
下载JAX-WS RI发行版。
将“jaxws-api.jar”复制到Tomcat库文件夹
“{$ TOMCAT} / lib中“。
重启Tomcat。