我正在使用 Spring Batch 设置将处理可能非常大的 XML 文件的作业。我想我已经正确设置了它,但是在运行时我发现作业运行,处理它的输入,然后只是挂在执行状态(我可以通过查看 JobRepository 中的 JobExecution 状态来确认)。
我已经多次阅读 Batch 文档,但没有看到任何明显的“输入不足时停止作业”配置。
这是我的应用程序上下文的相关部分:
<batch:job id="processPartnerUploads" restartable="true">
<batch:step id="processStuffHoldings">
<batch:tasklet>
<batch:chunk reader="stuffReader" writer="stuffWriter" commit-interval="1"/>
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="stuffReader" class="org.springframework.batch.item.xml.StaxEventItemReader">
<property name="fragmentRootElementName" value="stuff" />
<property name="resource" value="file:///path/to/file.xml" />
<property name="unmarshaller" ref="stuffUnmarshaller" />
</bean>
<bean id="stuffUnmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="com.company.project.xmlcontext"/>
</bean>
<bean id="stuffWriter" class="com.company.project.batch.StuffWriter" />
万一这很重要,“StuffWriter”只是一个记录将要写入的项目的类。
如果我错过了与 Batch 和/或 Stax 相关的一些重要细微差别,请告诉我。