Xmldatabinding配置,具有CXF-Spring-boot-Starter-Jaxws



我正在尝试使用AS DataBinding XMLBEAN使用Spring Boot CXF启动器发布服务:

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

如何解决此问题?

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

,或者您只需使用企业&amp;生产Ready Ready CXF-Spring-boot-Starter,值得它的名称 - 因为您不必关心wsdl4jxmlbeans。这件事可以为您带来一切,只需在一个普通的Spring Boot Project中使用它即可。以下pom.xml具有所有内容您需要 ever 用Spring Boot&amp;CXF:

<?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中的某个地方,它将生成所有需要的Java类文件,从您的WSDL,包括。服务端点接口(SEI(实现 - 使CXF-Spring-boot-starter启用>自动启动您的肥皂服务 - 首先100%合同!就像您知道春季靴世界中的所有其他框架一样。这也是一个完全有效的示例项目:https://github.com/codecentric/spring-samples/tree/master/cxf-boot-simple

剩下的唯一的东西是进行内部域模型或从内部域模型进行业务转换:

似乎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>

最新更新