Open
Description
When running a job with conditional flow, if steps in this job have the same name, the job doesn't behavior as expected (infinite loop on one step ...) because transitions in the job rely on step names. So in order to avoid such behavior, steps names in a flow job should be unique : spring batch should raise an exception or at least should log a warning.
Furthermore, in xml config, as step names are defined as ids of <step>
, they must be unique : it is an xsd constraint.
Here an example :
// Job definition :
public Job flowjob() {
return jobBuilderFactory.get("flowJob")
.start(step1())
.on("ODD").to(step2())
.from(step1()).on("EVEN").to(step3()
.from(step3()).next(step4())
.end()
.build();
}
// step1 definition with the name of step1 :
private Step step1() {
return stepBuilderFactory.get("step1").tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
String exitStatus = (System.currentTimeMillis() % 2 == 0) ? "EVEN" : "ODD";
contribution.setExitStatus(new ExitStatus(exitStatus));
return RepeatStatus.FINISHED;
}
})
.build();
}
//step2 definition with name of **step1** :
private Step step2() {
return stepBuilderFactory.get("step1") /*Big mistake !*/
.tasklet((contrib, chunk)->RepeatStatus.FINISHED)
.build();
}
// and so on : step3 and step4 are defined as step2 with always the same name (step1)
When running the job, spring batch loops infinitely on step3.