NoSuchMethodError - MtomStreamWriter.getAttachmentMarshaller()

NoSuchMethodError - MtomStreamWriter.getAttachmentMarshaller()

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

不过,我已经有了这样的class

下面是我用的全部dependency

<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>

我不明白为什么我会提前得到这样的error.Thanks答案。

我在 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中,此方法的return类型是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 的情况下工作正常。