代码之家  ›  专栏  ›  技术社区  ›  Hassen

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

  •  1
  • Hassen  · 技术社区  · 7 年前

    我正在尝试使用as数据绑定xmlbean发布一个带有Spring boot cxf starter的服务,如下所示:

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

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

    Java语言lang.NoSuchMethodError: 组织。阿帕奇。cxf。常见的jaxb。JAXBUtils。CreateMinumesCapeHandler

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

    <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 回复  |  直到 7 年前
        1
  •  0
  •   Shaaban Ebrahim    7 年前

    您可以使用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
  •  0
  •   jonashackt    6 年前

    或者您只需使用企业&生产就绪 cxf-spring-boot-starter 因为你不必关心 wsdl4j xmlbeans . 这个东西可以为您做任何事情,只需在普通的Spring Boot项目中使用它即可。以下内容 pom.xml 每件事 你需要 曾经 用弹簧靴和;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 它将从您的WSDL生成所有需要的Java类文件,包括服务端点接口(SEI)实现,这使cxf spring boot starter能够 自动地 启动您的SOAP服务-100%合同优先!正如您所知,Spring Boot领域中的所有其他框架。这里还有一个完全可行的示例项目: https://github.com/codecentric/spring-samples/tree/master/cxf-boot-simple

    剩下的唯一一件事就是在内部域模型中进行业务转换:)玩得开心!

        3
  •  0
  •   Edward Young    4 年前

    看来 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>