【问题标题】:Cannot create a secure XMLInputFactory when calling Apache CXF Client in spring boot application在 Spring Boot 应用程序中调用 Apache CXF 客户端时无法创建安全的 XMLInputFactory
【发布时间】:2018-12-24 16:15:31
【问题描述】:

我正在尝试在我的 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 时,第一行代码不会抛出指定的异常,但是当我尝试获取端口时,第二行代码会抛出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>
...

任何帮助将不胜感激。

【问题讨论】:

  • 您是否尝试添加以下依赖项:org.apache.cxfcxf-spring-boot-starter-jaxws3.1.12 ?见cxf.apache.org/docs/springboot.html
  • 完成了,但没有运气!但如果我没记错的话,这是为我尝试从端点使用的服务提供服务。
  • 虽然没有报告同样的问题,但看看这是否给你任何提示:mail-archives.apache.org/mod_mbox/cxf-users/201706.mbox/…。尽量不要从 spring-boot-starter-parent 继承。显式添加依赖项。也许你的依赖版本有冲突
  • 感谢@pringi,但是在 cfx 版本 3 之后删除了 woodstux 依赖
  • 我会尝试显式添加依赖项,然后将结果回复给您,谢谢

标签: java spring spring-boot cxf pom.xml


【解决方案1】:

经过大量搜索并在@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>

感谢大家!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-18
    相关资源
    最近更新 更多