Spring batch 如何使用决策器终止Spring批处理分割流中的步骤

Spring batch 如何使用决策器终止Spring批处理分割流中的步骤,spring-batch,Spring Batch,我在Spring批次中遇到了以下设计缺陷 步骤必须具有Next属性,除非它是拆分流的最后一步或最后一步 决策块必须处理决策者返回的所有案例 因此,在分割流中,最后一步不会有下一个属性,如果有决策者保护它,那么它必须有下一个属性。所以它不应该有那个属性,但它也需要它。第22条 例如: <!-- Process parallel steps --> <split id="split01"> <flow> <step id="step1

我在Spring批次中遇到了以下设计缺陷

  • 步骤必须具有Next属性,除非它是拆分流的最后一步或最后一步
  • 决策块必须处理决策者返回的所有案例
  • 因此,在分割流中,最后一步不会有下一个属性,如果有决策者保护它,那么它必须有下一个属性。所以它不应该有那个属性,但它也需要它。第22条

    例如:

    <!-- Process parallel steps -->
    <split id="split01">
        <flow>
            <step id="step1" next="step02">
                <!-- Do something -->
            </step>
            <step id="step02">
                <!-- Do something else -->
            </step>
        </flow>
        <flow>
            <step id="step03">
                <!-- Do something -->
            </step>
    
            <!-- Only run under specific conditions -->
            <decision id="decideToRunStep04" decider="isStepNeededDecider" >
                <next on="RUN" to="step04"/>
                <!-- Other state is "SKIP" -->
            </decision>
            <step id="step04">
                <!-- Conditionally do something-->
            </step>
        </flow>
    </split>
    
    <step id="step05" >
        <!-- Some more stuff -->
    </step>
    
    
    

    这似乎是Spring的人会想到的,所以好奇的是,实现这一点的正确、非黑客方式是什么。谢谢。

    如果没有人回答这个问题,我将提供我正在使用的黑客。它不美,但春天也不美

    创建要在无操作步骤中使用的无操作Tasklet

    public class NoopTasklet implements Tasklet {
        @Override
        public RepeatStatus execute(final StepContribution contribution,
                final ChunkContext chunkContext) throws Exception {
            return RepeatStatus.FINISHED;
        }
    }
    
    将NOOP tasklet添加到原始示例中的决策块

    <!-- Does nothing -->
    <bean id="noopTasklet" class="com.foo.NoopTasklet" />
    
    <!-- From example in question
    <decision id="decideToRunStep04" decider="isStepNeededDecider" >
        <next on="RUN" to="step04"/>
        <next on="SKIP" to="noop01"/>
    </decision>
    <step id="step04">
        <!-- Conditionally do something-->
    </step>
    <step id="noop01">
        <!-- Does nothing in the SKIP case
        <tasklet ref="noopTasklet" />
    </step>
    
    
    
    春天是城里最美丽的代码。 也就是说:

    <step id="step1" parent="s1">
        <end on="FAILED" />
        <next on="COMPLETED WITH SKIPS" to="errorPrint1" />
        <next on="*" to="step2" />
    </step>
    
    
    
    如XML中的。

    所述

    <batch:decision id="customerDecision" decider="customerDecider">
                <batch:next on="FILE_FAILURE" to="fileFailureStep" />
                <batch:next on="FILE_GENERATION" to="loadData" /> 
    </batch:decision>
    

    请参阅所述问题。这并不能解决问题。你是对的,我试图忽略“这是干净的,它对我的实现起到了作用”。我将其与我自己的decider实现结合使用,如图所示:@taher我不再能够访问该代码库,但您可以在这里看到decider的示例:
    public class CustomerDecider implements JobExecutionDecider {    
    @Override
    public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecutionStatus) {
    If(x)
        return new FlowExecutionStatus("FILE_FAILURE") ;
    else
        return new FlowExecutionStatus("FILE_GENERATION") ;
    }
    }