【问题标题】:Skip step based on job parameter根据作业参数跳过步骤
【发布时间】: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


    【解决方案1】:

    你不能用决策者做到这一点吗? http://docs.spring.io/spring-batch/reference/html/configureStep.html(第 5.3.4 章程序化流程决策)

    编辑:链接到更新的网址 https://docs.spring.io/spring-batch/trunk/reference/html/configureStep.html#programmaticFlowDecisions

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-30
      • 2023-03-19
      • 2017-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-08
      相关资源
      最近更新 更多