根据 Spring Batch 文档,Spring Batch 可以生成格式化的 xml 文件,但是我失败了,所有的 XML 元素都是一行生成的。
测试步骤
- 下载 spring-batch-2.1.9.RELEASE-no-dependencies
- 导入spring-*-3.2.0.RC1.jar
- 导入 jaxb-ri-2.2.6
- 运行 org.springframework.batch.sample.iosample.XmlFunctionalTests
在运行作业之前,我对 /spring-batch-2.1.9.RELEASE-no-dependencies/spring-batch-2.1.9.RELEASE/spring-batch-samples/src/main/resources/jobs/iosample 进行以下更改/xml.xml
<bean id="itemWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter">
<property name="resource" ref="outputResource" />
<property name="marshaller" ref="customerCreditMarshaller2" />
<property name="rootTagName" value="customers" />
<property name="overwriteOutput" value="true" />
</bean>
<bean id="customerCreditMarshaller2" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPaths">
<list>
<value>com.test.domain</value><!-- the package is generated from a XSD -->
</list>
</property>
<property name="marshallerProperties">
<map>
<entry key="jaxb.formatted.output"><value type="java.lang.Boolean">true</value></entry>
</map>
</property>