簡體   English   中英

春季批:條件流

[英]spring batch : Conditional Flow

我需要根據工作的第一步中的某些條件來決定,接下來要調用哪一步。

請注意:在Step1中,我使用的是純tasklet方法。 例:

<step id="step1">
   <tasklet ref="example">
</step>

請幫忙,我該如何在Example tasklet中放入一些代碼或進行一些配置,以決定要調用的下一步?

我已經看過https://docs.spring.io/spring-batch/reference/html/configureStep.html

您可以像這樣在上下文文件中指定流控制:

<step id="step1">
    <tasklet ref="example">
    <next on="COMPLETED" to="step2" />
    <end on="NO-OP" />
    <fail on="*" />
    <!-- 
      You generally want to Fail on * to prevent 
      accidentally doing the wrong thing
    -->
</step>

然后在你的Tasklet ,通過實施設定的退出狀態StepExecutionListener

public class SampleTasklet implements Tasklet, StepExecutionListener {

    @Override
    public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
        // do something
        return RepeatStatus.FINISHED;
    }

    @Override
    public void beforeStep(StepExecution stepExecution) {
        // no-op
    }

    @Override
    public ExitStatus afterStep(StepExecution stepExecution) {
        //some logic here
        boolean condition1 = false;
        boolean condition2 = true;

        if (condition1) {
            return new ExitStatus("COMPLETED");
        } else if (condition2) {
            return new ExitStatus("FAILED"); 
        }

        return new ExitStatus("NO-OP");
    }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM