【问题标题】:xmlDatabinding configuration with cxf-spring-boot-starter-jaxws带有 cxf-spring-boot-starter-jaxws 的 xmlDatabinding 配置
【发布时间】:2018-02-14 08:03:32
【问题描述】:

我正在尝试使用 Spring boot cxf starter 发布服务,使用 Databinding xmlbean,如下所示:

@Bean
public Endpoint nameServiceEndpoint() {
        EndpointImpl endpoint = new EndpointImpl(bus, new NameWsServiceImpl());
        endpoint.publish("/NamesWsService");
        endpoint.setDataBinding(new XmlBeansDataBinding());
     return endpoint;
}

当我尝试运行应用程序时出现以下错误:

java.lang.NoSuchMethodError: org.apache.cxf.common.jaxb.JAXBUtils.createMininumEscapeHandler

在我的 pom 中,我有依赖项:

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
    <version>3.2.2</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-databinding-xmlbeans</artifactId>
    <version>3.1.14</version>
</dependency>

我该如何解决这个问题?

【问题讨论】:

  • 如果解决方案好请投票
  • 感谢您的回复,我已经将您的回复标记为已解决
  • 为什么要混用不同的 CXF 版本?您应该对所有 CXF 依赖项使用相同的版本。

标签: java spring maven spring-boot cxf


【解决方案1】:

您可以使用 Spring Boot Web 服务,但您应该包含 wsdl4j

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
   <groupId>wsdl4j</groupId>
   <artifactId>wsdl4j</artifactId>
</dependency>

参考是https://spring.io/guides/gs/producing-web-service/

【讨论】:

    【解决方案2】:

    或者您只需使用企业和生产就绪的cxf-spring-boot-starter,它名副其实 - 因为您不必关心wsdl4jxmlbeans。这个东西为你做了一切,只需在一个普通的 Spring Boot 项目中使用它。以下pom.xml 拥有一切您需要曾经使用 Spring Boot 和 CXF 进行 SOAP:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>de.codecentric.soap</groupId>
        <artifactId>cxf-boot-simple</artifactId>
        <version>2.0.0-SNAPSHOT</version>
        <packaging>jar</packaging>
    
        <name>cxf-boot-simple</name>
        <description>Demo project for using Spring Boot Starter CXF</description>
    
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.2.RELEASE</version>
        </parent>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>cxf-spring-boot-starter</artifactId>
                <version>2.1.2.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>de.codecentric</groupId>
                    <artifactId>cxf-spring-boot-starter-maven-plugin</artifactId>
                    <version>2.0.0.RELEASE</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>
    

    配套的 Maven 插件 cxf-spring-boot-starter-maven-plugin 为您完成繁重的工作:只需将您的 wsdl 文件放在 src/main/resources 中的某个位置,它就会从您的 WSDL 生成所有需要的 Java 类文件,包括。服务端点接口 (SEI) 实现 - 使 cxf-spring-boot-starter 能够自动 启动您的 SOAP 服务 - 100% 优先签约!正如您了解 Spring Boot 世界中的所有其他框架一样。这里还有一个完整的示例项目:https://github.com/codecentric/spring-samples/tree/master/cxf-boot-simple

    剩下的唯一事情就是将业务转换为内部域模型或从内部域模型转换:) 玩得开心!

    【讨论】:

      【解决方案3】:

      似乎 cxf-spring-boot-starter-jaxws 依赖于一个缺少 createMininumEscapeHandler 的旧 jar。
      尝试通过 import cxf-bom 修复它,它对我有用!

      <!-- import cxf-bom -->
      <dependencyManagement>
        <dependencies>
           <dependency>
             <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-bom</artifactId>
             <version>3.4.0</version>
             <type>pom</type>
             <scope>import</scope>
           </dependency>
        </dependencies>
      </dependencyManagement>
      
      <dependencies>
        <!-- just cxf-spring-boot-starter-jaxws -->
        <dependency>
          <groupId>org.apache.cxf</groupId>
          <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
        </dependency>
      </dependencies>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-03-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-02
        • 1970-01-01
        • 2014-04-07
        • 2018-01-05
        • 2014-07-23
        相关资源
        最近更新 更多