0

我正在开发一个 spring 批处理程序来处理来自 sql 的数据并写入 xml。我使用 staxEventItemWriter 来做到这一点。但是由于这个问题https://jira.spring.io/browse/BATCH-1377我无法修复命名空间问题。当我们查看对这张 Jira 卡的评论时,它说它已在 2010 年修复。但它在我正在使用的最新 Spring Boot 版本中不可用。我尝试使用 Jira 卡中描述的补丁类,它对我来说工作正常。

<?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>com.demo.sitemap</groupId>
    <artifactId>SqlToXml</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>SqlToXml</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-batch</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>6.1.0.jre8</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-oxm -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>3.0.6.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>com.thoughtworks.xstream</groupId>
            <artifactId>xstream</artifactId>
            <version>1.4.10</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.0.4.RELEASE</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>
4

1 回答 1

0

如何验证我正在使用的 Spring Boot 版本中是否有 Spring 功能/Bug 修复?

您正在使用 Spring Boot 2.0.4.RELEASE。这将带来 Spring Batch 版本 4.0.1.RELEASE。您可以使用 Spring Boot Initializr REST API找到有关依赖项的更多详细信息。

问题BATCH-1377在版本 2.1.0.RC1 中标记为已解决,并且在 4.0.1.RELEASE 中也可用。

但它在我正在使用的最新 Spring Boot 版本中不可用。我尝试使用 Jira 卡中描述的补丁类,它对我来说工作正常。

贡献者建议的补丁使用了一个额外的属性rootTagNamePrefix,但根据此评论对其进行了修改以使用命名约定{uri}prefix:root,以便与 Spring WS 保持一致。问题已在此处修复:https ://github.com/spring-projects/spring-batch/commit/f56ee747296961917caa38fa9e14785dafc0b18b

因此,在您的情况下,如果要将命名空间添加到根标记,则需要使用此命名约定。请参阅此处的示例:https ://github.com/spring-projects/spring-batch/blob/f56ee747296961917caa38fa9e14785dafc0b18b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java# L287

于 2018-09-20T08:45:44.530 回答