【问题标题】:CXFServlet throws java.lang.NoSuchMethodError: org.codehaus.stax2.ri.EmptyIterator.getInstance()Lorg/codehaus/stax2/ri/EmptyIterator;CXFServlet 抛出 java.lang.NoSuchMethodError: org.codehaus.stax2.ri.EmptyIterator.getInstance()Lorg/codehaus/stax2/ri/EmptyIterator;
【发布时间】:2019-05-28 03:31:40
【问题描述】:

我正在使用 Java 11、Spring Boot 2.1.1 和 Apache CXF 3.2.7 来公开导入 XSD 架构的 SOAP Web 服务。在 WSDL 中显示如下:

<wsdl:import location="http://localhost:9000/endpoint/ws?wsdl=WS_endpointSoapPort.wsdl" namespace="http://test.com"> </wsdl:import>

当我发送查询时,它会因以下堆栈而失败:

2018-12-31 12:05:54,908 ERROR se.[Tomcat].[localhost].[/].[CXFServlet]: 175 - Servlet.service() for servlet [CXFServlet] in context with path [] threw exception [Servlet execution threw an exception] with root cause
java.lang.NoSuchMethodError: org.codehaus.stax2.ri.EmptyIterator.getInstance()Lorg/codehaus/stax2/ri/EmptyIterator;

有什么想法吗?

【问题讨论】:

    标签: java web-services soap cxf stax


    【解决方案1】:

    密钥可能在您的mvn:dependency-tree 输出中。就我而言:

    [INFO]    \- org.apache.cxf:cxf-rt-ws-security:jar:3.3.6:compile
    [INFO]       +- org.apache.cxf:cxf-core:jar:3.3.6:compile
    [INFO]       |  \- com.fasterxml.woodstox:woodstox-core:jar:5.3.0:compile (version managed from 5.0.3)
    [INFO]       |     \- org.codehaus.woodstox:stax2-api:jar:4.2:compile
    [INFO]       \- org.apache.wss4j:wss4j-policy:jar:2.2.5:compile
    [INFO]          \- org.apache.neethi:neethi:jar:3.1.1:compile
    [INFO]             \- org.codehaus.woodstox:woodstox-core-asl:jar:4.4.1:compile
    [INFO]                \- (org.codehaus.woodstox:stax2-api:jar:3.1.4:compile - omitted for conflict with 4.2)
    

    org.apache.cxf:cxf-rt-ws-security:jar:3.3.6 导致 stax2-api 版本 3.1.4 和 4.2 版本,因为非常过时的 woodstox-core-asl 依赖项(从 2014 年开始)。我将不得不看看我是否可以摆脱它,因为它会导致上面描述的 NoSuchMethodFoundError。

    【讨论】:

      【解决方案2】:

      我在 Maven 中使用不同版本的 stax2-api 的一些依赖项遇到了同样的问题。

      Maven 编译器仅使用一个版本的 stax2-api(在我的例子中是最新的),所以我尝试使用 runtime 包含版本 3.1.4 和 4.2.1(其他 jar 需要)范围

      这里是 pom.xml 的片段

      <dependency>
        <groupId>org.codehaus.woodstox</groupId>
        <artifactId>stax2-api</artifactId>
        <version>4.2.1</version>
        <scope>runtime</scope>
      </dependency>
           
      <dependency>
        <groupId>org.codehaus.woodstox</groupId>
        <artifactId>stax2-api</artifactId>
        <version>3.1.4</version>
        <scope>runtime</scope>
      </dependency>
      

      备注:在我的情况下,它在将类作为 java 应用程序 执行时有效,但在 Web 应用程序 中执行时无效环境(Tomcat)!

      【讨论】:

      • 永远不应该这样做。您添加了两次相同的工件(唯一的区别是版本),因此类加载器可以访问两者,但是加载的内容取决于类加载器,它通常只会加载 1 个具有相同签名的类。它对您的行为不同并且有效/无效的事实是因为类加载器以不同的顺序搜索类。
      【解决方案3】:

      我在 org.codehaus.woodstox:stax2-api 上存在冲突,它包含在 org.apache.cxf:cxf-core 的 3.1.4 版和 com.sun.xml.ws:rt 的 4.1 版中。我通过使用 Maven excludes 删除库解决了冲突:

              <exclusions>
                  <exclusion>
                      <groupId>org.codehaus.woodstox</groupId>
                      <artifactId>stax2-api</artifactId><!-- 4.1 conflicts with 3.1.4 from apache cxf-spring-boot-starter-jaxws-->
                  </exclusion>
              </exclusions>
      

      【讨论】:

        【解决方案4】:

        我遇到了同样的问题,升级到 CXF 3.2.7 或更高版本为我解决了这个问题。

        【讨论】:

        • 其实我只是在升级到 CXF 3.3.6 时才遇到这个问题,所以值得深入挖掘依赖树。
        • 可以确认3.3.7
        【解决方案5】:

        经过深入研究,我发现以下JIRA提到了Stax2版本的问题。顺便说一句,票说它可以解决我正在使用的版本。

        最后,我修复了升级到 woodstox-core-5.2.0 的问题。事实上,该库提到了在该版本中解决的类似问题。详情here

        我现在的mvn dependency:tree 是:

        [INFO] +- org.springframework.boot:spring-boot-starter:jar:2.1.1.RELEASE:compile
        [INFO] |  +- org.springframework.boot:spring-boot:jar:2.1.1.RELEASE:compile
        [INFO] |  |  \- org.springframework:spring-context:jar:5.1.3.RELEASE:compile
        [INFO] |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.1.1.RELEASE:compile
        [INFO] |  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile
        [INFO] |  |  |  \- ch.qos.logback:logback-core:jar:1.2.3:compile
        [INFO] |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.11.1:compile
        [INFO] |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.11.1:compile
        [INFO] |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
        [INFO] |  +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
        [INFO] |  +- org.springframework:spring-core:jar:5.1.3.RELEASE:compile
        [INFO] |  |  \- org.springframework:spring-jcl:jar:5.1.3.RELEASE:compile
        [INFO] |  \- org.yaml:snakeyaml:jar:1.23:runtime
        [INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.1.1.RELEASE:compile
        [INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.1.1.RELEASE:compile
        [INFO] |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.7:compile
        [INFO] |  |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
        [INFO] |  |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.9.7:compile
        [INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.7:compile
        [INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.7:compile
        [INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.7:compile
        [INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.1.1.RELEASE:compile
        [INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.13:compile
        [INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.13:compile
        [INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.13:compile
        [INFO] |  +- org.hibernate.validator:hibernate-validator:jar:6.0.13.Final:compile
        [INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
        [INFO] |  |  \- com.fasterxml:classmate:jar:1.4.0:compile
        [INFO] |  +- org.springframework:spring-web:jar:5.1.3.RELEASE:compile
        [INFO] |  |  \- org.springframework:spring-beans:jar:5.1.3.RELEASE:compile
        [INFO] |  \- org.springframework:spring-webmvc:jar:5.1.3.RELEASE:compile
        [INFO] |     +- org.springframework:spring-aop:jar:5.1.3.RELEASE:compile
        [INFO] |     \- org.springframework:spring-expression:jar:5.1.3.RELEASE:compile
        [INFO] +- org.springframework.boot:spring-boot-autoconfigure:jar:2.1.1.RELEASE:compile
        [INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.1.1.RELEASE:test
        [INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.1.1.RELEASE:test
        [INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.1.1.RELEASE:test
        [INFO] |  +- com.jayway.jsonpath:json-path:jar:2.4.0:test
        [INFO] |  |  \- net.minidev:json-smart:jar:2.3:test
        [INFO] |  |     \- net.minidev:accessors-smart:jar:1.2:test
        [INFO] |  +- junit:junit:jar:4.12:test
        [INFO] |  +- org.assertj:assertj-core:jar:3.11.1:test
        [INFO] |  +- org.mockito:mockito-core:jar:2.23.4:test
        [INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.9.5:test
        [INFO] |  |  +- net.bytebuddy:byte-buddy-agent:jar:1.9.5:test
        [INFO] |  |  \- org.objenesis:objenesis:jar:2.6:test
        [INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
        [INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
        [INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.0:test
        [INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
        [INFO] |  +- org.springframework:spring-test:jar:5.1.3.RELEASE:test
        [INFO] |  \- org.xmlunit:xmlunit-core:jar:2.6.2:test
        [INFO] +- org.apache.cxf:cxf-spring-boot-starter-jaxws:jar:3.2.7:compile
        [INFO] |  +- org.apache.cxf:cxf-spring-boot-autoconfigure:jar:3.2.7:compile
        [INFO] |  +- org.apache.cxf:cxf-rt-frontend-jaxws:jar:3.2.7:compile
        [INFO] |  |  +- xml-resolver:xml-resolver:jar:1.2:compile
        [INFO] |  |  +- org.ow2.asm:asm:jar:6.2:compile
        [INFO] |  |  +- org.apache.cxf:cxf-rt-bindings-xml:jar:3.2.7:compile
        [INFO] |  |  +- org.apache.cxf:cxf-rt-frontend-simple:jar:3.2.7:compile
        [INFO] |  |  \- org.apache.cxf:cxf-rt-ws-addr:jar:3.2.7:compile
        [INFO] |  |     \- org.apache.cxf:cxf-rt-ws-policy:jar:3.2.7:compile
        [INFO] |  \- javax.validation:validation-api:jar:2.0.1.Final:compile
        [INFO] +- com.fasterxml.woodstox:woodstox-core:jar:5.2.0:compile
        [INFO] |  \- org.codehaus.woodstox:stax2-api:jar:4.1:compile
        [INFO] +- org.apache.cxf:cxf-rt-transports-http:jar:3.2.7:compile
        [INFO] |  \- org.apache.cxf:cxf-core:jar:3.2.7:compile
        [INFO] |     \- org.apache.ws.xmlschema:xmlschema-core:jar:2.2.3:compile
        [INFO] +- org.apache.cxf:cxf-rt-ws-security:jar:3.2.7:compile
        [INFO] |  +- org.apache.cxf:cxf-rt-bindings-soap:jar:3.2.7:compile
        [INFO] |  |  +- org.apache.cxf:cxf-rt-wsdl:jar:3.2.7:compile
        [INFO] |  |  |  \- wsdl4j:wsdl4j:jar:1.6.3:compile
        [INFO] |  |  \- org.apache.cxf:cxf-rt-databinding-jaxb:jar:3.2.7:compile
        [INFO] |  +- org.apache.cxf:cxf-rt-security-saml:jar:3.2.7:compile
        [INFO] |  |  \- org.apache.cxf:cxf-rt-security:jar:3.2.7:compile
        [INFO] |  +- net.sf.ehcache:ehcache:jar:2.10.6:compile
        [INFO] |  +- org.apache.wss4j:wss4j-ws-security-dom:jar:2.2.2:compile
        [INFO] |  |  \- org.apache.wss4j:wss4j-ws-security-common:jar:2.2.2:compile
        [INFO] |  |     +- org.apache.santuario:xmlsec:jar:2.1.2:compile
        [INFO] |  |     |  \- commons-codec:commons-codec:jar:1.11:compile
        [INFO] |  |     +- org.opensaml:opensaml-saml-impl:jar:3.3.0:compile
        [INFO] |  |     |  +- org.opensaml:opensaml-profile-api:jar:3.3.0:compile
        [INFO] |  |     |  |  \- org.opensaml:opensaml-core:jar:3.3.0:compile
        [INFO] |  |     |  |     \- io.dropwizard.metrics:metrics-core:jar:4.0.3:compile
        [INFO] |  |     |  +- org.opensaml:opensaml-saml-api:jar:3.3.0:compile
        [INFO] |  |     |  |  +- org.opensaml:opensaml-xmlsec-api:jar:3.3.0:compile
        [INFO] |  |     |  |  \- org.opensaml:opensaml-soap-api:jar:3.3.0:compile
        [INFO] |  |     |  +- org.opensaml:opensaml-security-impl:jar:3.3.0:compile
        [INFO] |  |     |  |  \- org.opensaml:opensaml-security-api:jar:3.3.0:compile
        [INFO] |  |     |  |     +- org.cryptacular:cryptacular:jar:1.1.1:compile
        [INFO] |  |     |  |     \- org.bouncycastle:bcprov-jdk15on:jar:1.54:compile
        [INFO] |  |     |  +- org.opensaml:opensaml-xmlsec-impl:jar:3.3.0:compile
        [INFO] |  |     |  \- net.shibboleth.utilities:java-support:jar:7.3.0:compile
        [INFO] |  |     |     +- com.google.guava:guava:jar:19.0:compile
        [INFO] |  |     |     \- joda-time:joda-time:jar:2.10.1:compile
        [INFO] |  |     +- org.opensaml:opensaml-xacml-impl:jar:3.3.0:compile
        [INFO] |  |     |  \- org.opensaml:opensaml-xacml-api:jar:3.3.0:compile
        [INFO] |  |     +- org.opensaml:opensaml-xacml-saml-impl:jar:3.3.0:compile
        [INFO] |  |     |  \- org.opensaml:opensaml-xacml-saml-api:jar:3.3.0:compile
        [INFO] |  |     +- org.jasypt:jasypt:jar:1.9.2:compile
        [INFO] |  |     \- org.apache.geronimo.javamail:geronimo-javamail_1.4_mail:jar:1.8.4:compile
        [INFO] |  +- org.apache.wss4j:wss4j-policy:jar:2.2.2:compile
        [INFO] |  |  \- org.apache.neethi:neethi:jar:3.1.1:compile
        [INFO] |  |     \- org.codehaus.woodstox:woodstox-core-asl:jar:4.4.1:compile
        [INFO] |  |        \- javax.xml.stream:stax-api:jar:1.0-2:compile
        [INFO] |  +- org.apache.wss4j:wss4j-ws-security-stax:jar:2.2.2:compile
        [INFO] |  |  \- org.apache.wss4j:wss4j-bindings:jar:2.2.2:compile
        [INFO] |  \- org.apache.wss4j:wss4j-ws-security-policy-stax:jar:2.2.2:compile
        [INFO] +- org.apache.cxf:cxf-rt-features-logging:jar:3.2.7:compile
        [INFO] |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
        [INFO] +- org.apache.commons:commons-lang3:jar:3.8.1:compile
        [INFO] +- org.glassfish.jaxb:jaxb-runtime:jar:2.4.0-b180830.0438:compile
        [INFO] |  +- javax.xml.bind:jaxb-api:jar:2.3.1:compile
        [INFO] |  +- org.glassfish.jaxb:txw2:jar:2.4.0-b180830.0438:compile
        [INFO] |  +- com.sun.istack:istack-commons-runtime:jar:3.0.7:compile
        [INFO] |  +- org.jvnet.staxex:stax-ex:jar:1.8:compile
        [INFO] |  +- com.sun.xml.fastinfoset:FastInfoset:jar:1.2.15:compile
        [INFO] |  \- javax.activation:javax.activation-api:jar:1.2.0:compile
        [INFO] +- com.sun.xml.ws:jaxws-rt:pom:2.3.1:compile
        [INFO] |  +- javax.xml.ws:jaxws-api:jar:2.3.1:compile
        [INFO] |  +- javax.xml.soap:javax.xml.soap-api:jar:1.4.0:compile
        [INFO] |  +- javax.jws:javax.jws-api:jar:1.1:compile
        [INFO] |  +- com.sun.xml.ws:policy:jar:2.7.5:compile
        [INFO] |  |  \- com.sun.activation:javax.activation:jar:1.2.0:compile
        [INFO] |  +- org.glassfish.gmbal:gmbal-api-only:jar:3.1.0-b001:compile
        [INFO] |  |  \- org.glassfish.external:management-api:jar:3.0.0-b012:compile
        [INFO] |  +- com.sun.xml.stream.buffer:streambuffer:jar:1.5.6:compile
        [INFO] |  +- org.jvnet.mimepull:mimepull:jar:1.9.10:compile
        [INFO] |  +- org.glassfish.ha:ha-api:jar:3.1.9:compile
        [INFO] |  \- com.sun.xml.messaging.saaj:saaj-impl:jar:1.5.0:compile
        [INFO] \- com.sun.xml.ws:rt:jar:2.3.1:compile
        

        【讨论】:

        • 感谢 apache jira page 的链接。我能够通过从 cxf-rt-ws-security 依赖项中排除旧版本的 woodstox-core-asl 来解决问题。
        猜你喜欢
        • 2021-03-15
        • 1970-01-01
        • 2018-08-22
        • 2013-03-17
        • 2015-08-03
        • 2020-12-01
        • 1970-01-01
        • 2020-05-20
        • 2012-02-06
        相关资源
        最近更新 更多