我正在尝试在我的 Spring Boot 应用程序中使用服务。这个确切的客户端在 netbeans 和使用 spring 3 MVC 的旧项目中运行良好,但是当我尝试调用相同的方法时,我得到 javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: java.lang.RuntimeException: Cannot create a secure XMLInputFactory
.
我搜索了很多并尝试了不同的答案,但没有运气!这些是我尝试过的 stackoverflow 上的一些问题:
CXF web service client: "Cannot create a secure XMLInputFactory"
java.lang.RuntimeException: Cannot create a secure XMLInputFactory when deploying on Glassfish
Cannot create a secure XMLInputFactory
Cannot create a secure XMLInputFactory when calling Apache CXF Client from Plain Java
尽管传递 VM 选项以允许不太安全的解析器对我来说不是一个解决方案,但我尝试了这一点。当我添加-Dorg.apache.cxf.stax.allowInsecureParser=1
时第一行代码不会抛出指定的异常,而是在我尝试获取端口 a java.lang.NoSuchFieldError: QUALIFIED
时在第二行抛出将会被抛出!
调用服务的代码:
MessageRelayService messageRelayService = new MessageRelayService();
MessageRelay msgService = messageRelayService.getMessageRelayPort();
CountResult countResult = msgService.getReceivedMessageCount(USERNAME, PASSWORD);
我的pom(为简洁起见,省略了一些部分):
<properties>
...
<java.version>1.8</java.version>
<cxf.version>3.0.0</cxf.version>
<swagger.version>2.6.0</swagger.version>
<purchase.version>1.2.4</purchase.version>
<spring-cloud.version>Camden.SR2</spring-cloud.version>
...
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
.
.
.
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-impl</artifactId>
<version>1.2.13</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
.
.
.
</dependencies>
...
任何帮助将不胜感激。
最佳答案
在 @pringi 的帮助下进行了大量搜索并尝试了各种事情之后,我回到了我的 pom 并发现了问题,所以我想写一个答案也许有一天它会对某人有所帮助!
问题是我的 pom 中有一些不需要的依赖项,它们可以被删除,并且它们与 cxf 冲突!所以我删除了这些依赖项,瞧!
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-impl</artifactId>
<version>1.2.13</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.neethi</groupId>
<artifactId>neethi</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
<version>1.2.13</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.schema</groupId>
<artifactId>XmlSchema</artifactId>
<version>1.4.2</version>
</dependency>
感谢大家!
关于java - 在 Spring Boot 应用程序中调用 Apache CXF 客户端时无法创建安全的 XMLInputFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51373279/