【发布时间】:2015-12-18 01:30:32
【问题描述】:
我已经通读了几次 Spring Batch 文档,并搜索了一种基于作业参数跳过作业步骤的方法。
比如说我有这份工作
<batch:job id="job" restartable="true"
xmlns="http://www.springframework.org/schema/batch">
<batch:step id="step1-partitioned-export-master">
<batch:partition handler="partitionHandler"
partitioner="partitioner" />
<batch:next on="COMPLETED" to="step2-join" />
</batch:step>
<batch:step id="step2-join">
<batch:tasklet>
<batch:chunk reader="xmlMultiResourceReader" writer="joinXmlItemWriter"
commit-interval="1000">
</batch:chunk>
</batch:tasklet>
<batch:next on="COMPLETED" to="step3-zipFile" />
</batch:step>
<batch:step id="step3-zipFile">
<batch:tasklet ref="zipFileTasklet" />
<!-- <batch:next on="COMPLETED" to="step4-fileCleanUp" /> -->
</batch:step>
<!-- <batch:step id="step4-fileCleanUp">
<batch:tasklet ref="fileCleanUpTasklet" />
</batch:step> -->
</batch:job>
如果需要,我希望能够通过在作业参数中指定来跳过第 4 步。
我能找到的唯一有点相关的问题是how to select which spring batch job to run based on application argument - spring boot java config
这似乎表明应创建 2 个不同的作业上下文,并在批处理步骤定义之外做出决定。
我已经遵循了这种模式,因为我有一个 csv 导出以及示例中的 xml。我将 2 个作业拆分为每个导出类型的一个 spring-context.xml 文件,即使那里没有太多差异。
当时我认为它可能更干净,因为我找不到替代品的例子。
但是必须创建 4 个单独的上下文文件才能为每个导出案例包含或不包含第 4 步似乎有点疯狂。
我一定是错过了什么。
【问题讨论】:
标签: spring-batch