Web Services CXFServlet抛出java.lang.无此类方法错误:()获取示例()返回/返回/返回空迭代器;

mkh04yzy  于 2022-12-29  发布在  Java
关注(0)|答案(6)|浏览(148)

我使用Java 11、Sping Boot 2.1.1和Apache CXF 3.2.7来公开一个导入XSD模式的SOAP Web服务。

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

有什么想法吗?

yebdmbv4

yebdmbv41#

我在org.apache.cxf:cxf-core中的3.1.4版本和com.sun.xml.ws:rt中的4.1版本中遇到了org.codehaus.woodstox:stax2-api冲突。我通过使用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>
qybjjes1

qybjjes12#

经过深入研究,我发现下面的JIRA提到了Stax 2版本的问题。顺便说一句,票说,它解决了我正在使用的版本。
最后,我修复了升级到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
qfe3c7zg

qfe3c7zg3#

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

gxwragnw

gxwragnw4#

密钥可能在您的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导致stax 2-API的版本3.1.4和版本4.2,因为非常过时的woodstox-core-asl依赖项(从2014年开始)。我将不得不看看我是否可以摆脱这个,因为它导致上面描述的NoSuchMethodFoundError。

ca1c2owp

ca1c2owp5#

这问题是在新版本的stax2-api新方法被添加.你能解决这问题通过添加新版本的stax2-api.在我的情况添加

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

解决了问题。

bwleehnv

bwleehnv6#

我在Maven中的一些依赖项也遇到了同样的问题,这些依赖项使用了不同版本的stax 2-API
Maven编译器只使用一个版本的stax 2-API(在我的例子中,它是最新的),所以我尝试使用runtime scope包含版本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)中执行时无效!

相关问题