使用cxf-spring-boot-starter-jaxws进行xmlDatabinding配置

时间:2018-02-14 08:03:33

标签: java spring maven spring-boot cxf

我尝试使用Spring引导cxf启动器使用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>

我该如何解决这个问题?

3 个答案:

答案 0 :(得分:0)

您可以使用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/

答案 1 :(得分:0)

或者您只需要使用已准备好用于企业和生产环境的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

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

答案 2 :(得分:0)

似乎cxf-spring-boot-starter-jaxws依赖于缺少createMininumEscapeHandler的旧罐子。
尝试通过导入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>