2015년 7월 29일 수요일

Spring-Batch Conditional Step Flow

Spring Batch Step Conditional Flow (Java Config)

fail
success
fail
success
StepA
StepC
StepB
StepD
<job id="job">
    <step id="stepA" parent="s1">
        <next on="*" to="stepB" />
        <next on="FAILED" to="stepC" />
    </step>
    <step id="stepB" parent="s2" next="stepC">
         <next on="*" to="stepD" />
         <next on="FAILED" to="stepC" />
    </step>
    <step id="stepC" parent="s3" />
    <step id="stepD" parent="s4" />
</job>
  • java Config

public Job job(Tasklet01 tasklet01, Tasklet02 tasklet02, Tasklet03 tasklet03, Tasklet04 tasklet04,) {
    return JobBuilderFactory.get("jobNmae")
                            .start(stepA(tasklet01))
                                .on("FAILED").to(StepC(tasklet03))
                            .from(StepA(tasklet01))
                            .next(StepB(tasklet02))
                                .on("FAILED").to(StepC(tasklet03))
                            .from(StepB(tasklet02))
                                .next(StepD(tasklet04))
                            .end()
                            .build();
  • You can control ExitSatus which is used on(“HERE”) using spring batch Context for example :
    I wrote the below code in Tasklet.
chunkContext.getStepContext().getStepExecution().setStatus(BatchStatus.FAILED);"

hope this help you!


댓글 1개:

  1. Awesome thanks i was looking for this, this way is so much better and cleaner than if else approach. i'm facing a test framework for two applications very similar but in some points or process they differ
    so i can add extra steps or distinct steps whether if it's one app or another

    답글삭제