jakarta-ee - NoSuchMethodError - MtomStreamWriter.getAttachmentMarshaller() 方法

标签 jakarta-ee wsdl jax-ws java-11 mtom

我正在使用 wsdl 连接,当我收到响应时,出现如下错误。

enter image description here

但是,我已经有了这样一个

enter image description here

下面是我使用的所有依赖

<dependencies>
    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-tools</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-rt</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>javax.jws</groupId>
        <artifactId>javax.jws-api</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>javax.xml.ws</groupId>
        <artifactId>jaxws-api</artifactId>
        <version>2.3.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>rt</artifactId>
        <version>2.3.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.stream.buffer</groupId>
        <artifactId>streambuffer</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>org.jvnet.staxex</groupId>
        <artifactId>stax-ex</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>javax.xml.soap</groupId>
        <artifactId>javax.xml.soap-api</artifactId>
        <version>1.4.0</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.messaging.saaj</groupId>
        <artifactId>saaj-impl</artifactId>
        <version>1.5.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.gmbal</groupId>
        <artifactId>gmbal-api-only</artifactId>
        <version>4.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.jvnet.staxex</groupId>
        <artifactId>stax-ex</artifactId>
        <version>2.0.0</version>
    </dependency>

</dependencies>

我不明白为什么会出现这样的错误。在此先感谢您的回答。

最佳答案

我在 Jakarta 和启用 MTOM 后遇到了同样的问题。
我现在使用 Java 17

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: 'jakarta.xml.bind.attachment.AttachmentMarshaller org.jvnet.staxex.util.MtomStreamWriter.getAttachmentMarshaller()'

stax-ex-1.8.jar中,该方法的返回类型是javax.xml.bind.attachment.AttachmentMarshaller,不是预期的jakarta .xml.bind.attachment.AttachmentMarshaller 显示在错误消息中。

这是我的 pom.xml 中有问题的依赖项:

...
<dependency> <!-- Not good -->
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.1</version>
</dependency>
<dependency> <!-- Not good -->
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.1</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>jakarta.xml.ws</groupId>
    <artifactId>jakarta.xml.ws-api</artifactId>
    <version>3.0.1</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-rt</artifactId>
    <version>3.0.2</version>
</dependency>
...

以下是新的良好依赖项:

...
<!-- JAXB API v3.0.1 -->
<dependency>
    <groupId>jakarta.xml.bind</groupId>
    <artifactId>jakarta.xml.bind-api</artifactId>
    <version>3.0.1</version>
</dependency>
<!-- JAXB v3.0.2 reference implementation -->
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>3.0.2</version>
    <scope>runtime</scope>
</dependency>

<dependency>
    <groupId>jakarta.xml.ws</groupId>
    <artifactId>jakarta.xml.ws-api</artifactId>
    <version>3.0.1</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-rt</artifactId>
    <version>3.0.2</version>
</dependency>
...

stax-ex-1.8.jar 现在被替换为 stax-ex-2.0.1.jar
然后,我的客户端网络服务 Jakarta JAX-WS 在启用 MTOM 的情况下工作正常。

关于jakarta-ee - NoSuchMethodError - MtomStreamWriter.getAttachmentMarshaller() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67258558/

相关文章:

java - 如何在远程 ejb 查找期间设置超时?

java ee - 使用 servlet 对用户进行身份验证

java - 如何在发送重定向时存储 session

soap - IntelliJ 不会使用 Apache Axis 2 从 Java 代码生成 WSDL

java - 使用 JAX-WS 的并发 Web 服务请求

java - 如何从字符串或输入流执行 jax-ws soap 请求

java - 如何从 Web 服务方法访问 WebContent 文件夹

java - 为 2 个不同版本构建 Ant

java - 发布集合中的 wsdl 模式名称冲突

perl - 使用 SOAP::Lite 服务 stub