我的jdk版本是11,用了这些jar包:" <dependency> <groupId>com.sun.xml.messaging.saaj</groupId> <artifactId>saaj-impl</artifactId> <version>3.0.2</version> </dependency> <!-- https://mvnrepository.com/artifact/jakarta.xml.ws/jakarta.xml.ws-api --> <dependency> <groupId>jakarta.xml.ws</groupId> <artifactId>jakarta.xml.ws-api</artifactId> <version>4.0.0</version> </dependency> <!-- https://mvnrepository.com/artifact/com.sun.xml.ws/jaxws-rt --> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-rt</artifactId> <version>4.0.1</version> </dependency> <!-- https://mvnrepository.com/artifact/jakarta.xml.soap/jakarta.xml.soap-api --> <dependency> <groupId>jakarta.xml.soap</groupId> <artifactId>jakarta.xml.soap-api</artifactId> <version>3.0.0</version> </dependency> <!-- https://mvnrepository.com/artifact/jakarta.activation/jakarta.activation-api --> <dependency> <groupId>jakarta.activation</groupId> <artifactId>jakarta.activation-api</artifactId> <version>2.1.2</version> </dependency> ";但是在tomcat中运行这里的代码" private static MessageFactory getSOAPMsgFactory() throws SOAPException { if (_msgFact == null) { _msgFact = MessageFactory.newInstance(); } return _msgFact; }",会抛出异常:"jakarta.xml.soap.SOAPException: Unable to create message factory for SOAP: Unable to create SAAJ meta-factory: Provider com.sun.xml.messaging.saaj.soap.SAAJMetaFactoryImpl not found at jakarta.xml.soap.MessageFactory.newInstance(MessageFactory.java:96) at com.firstronix.webservice.WebServiceUtils.getSOAPMsgFactory(WebServiceUtils.java:80) at com.firstronix.webservice.WebServiceUtils.newBlankSOAPMessage(WebServiceUtils.java:130)",我该如何修复这个bug
时间: 2023-07-09 16:37:25 浏览: 296
jdk10+ java.lang.NoClassDefFoundError: javax/xml/ws/Service 错误
这个问题可能是由于缺少 SAAJMetaFactory 实现引起的。您可以尝试将以下依赖项添加到您的 Maven 项目中:
```xml
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-ri</artifactId>
<version>1.5.1</version>
</dependency>
```
如果您使用的是 Gradle,则可以将以下内容添加到您的 build.gradle 文件中:
```groovy
implementation 'com.sun.xml.messaging.saaj:saaj-ri:1.5.1'
```
这将添加 SAAJMetaFactory 的实现类,从而解决该问题。
阅读全文