2016-04-26 8 views
2

ジョブのステップ1の条件に基づいて、次に呼び出すステップを決定する必要があります。スプリングバッチ:条件付きフロー

注意:Step1では、私は純粋なタスクレットアプローチを使用しています。例:

例題のタスクレットにいくつかのコードを挿入するか、いくつかの設定を呼び出して次のステップを呼び出すことができますか?

私はすでにあなたがそうのようなあなたのコンテキストファイル内のフロー制御を指示することができますhttps://docs.spring.io/spring-batch/reference/html/configureStep.html

答えて

3

に見てきました:

<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"); 
    } 

} 
を実装することにより、終了ステータスを設定