我有一个项目编写器配置如下,它生成一个 xml:
<beans:bean id="delegateItemWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter" scope="step">
<beans:property name="resource" value="file:#{jobParameters['OutputDirPath']}${myFileName}" />
<beans:property name="overwriteOutput" value="true"/>
<beans:property name="rootTagName" value="disclosure-feed" />
<beans:property name="rootElementAttributes" >
<beans:map>
<beans:entry key="xmlns:xsi" value="http://www.w3.org/2001/XMLSchema-instance" />
<beans:entry key="xsi:noNamespaceSchemaLocation" value="XYZ.xsd"/>
</beans:map>
</beans:property>
<beans:property name="marshaller" ref="xmlMarshaller" />
</beans:bean>
尽管一切看起来都是正确的,但有时在修复先前运行的失败后重新启 Action 业时,我会收到以下错误:
2013-07-19 02:14:34,921 [main] ERROR org.springframework.batch.core.step.AbstractStep - Encountered an error executing the step
org.springframework.batch.item.ItemStreamException: File is not writable: [/myOutputDir/myOutput.xml]
当我手动从batch_表中删除作业条目以便作业从头开始而不是从上次运行期间失败的位置重新启动时,文件将按预期生成。
这个问题的原因是什么? 如何解决呢?我缺少一些配置吗?
感谢您的阅读!
最佳答案
看起来像 org.springframework.batch.item.utilFileUtils.java 中的错误,Spring 批处理期望在第一次运行时已经创建的文件。
if (!restarted) {
if (file.exists()) {
...
}
if (file.getParent() != null) {
new File(file.getParent()).mkdirs();
}
file.createNewFile();
}
if (!file.canWrite()) {
throw new ItemStreamException("File is not writable...");
}
如果是重新启动,则不会创建任何文件,因此您会收到异常。
关于java - StaxEventItemWriter - 文件不可写问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17741511/