Description
The conditional flow does not work as stated in the official documentation (https://docs.spring.io/spring-batch/docs/current/reference/html/step.html#controllingStepFlow)
Tried with:
Spring Boot: 2.6.7 >> <spring-batch.version>4.3.5</spring-batch.version> >> Java8
Spring Boot: 2.6.9 >> <spring-batch.version>4.3.6</spring-batch.version> >> Java8
@Bean
public Job job() {
return this.jobBuilderFactory.get("job")
.start(stepA())
.on("*").to(stepB())
.from(stepA()).on("FAILED").to(stepC())
.end()
.build();
}
If I use the above example, then:
stepA()
is completed successfully then it runs ok to stepB()
>> as expected
stepA()
fails then step stepB()
is executed >> expected stepC()
to be executed but instead it was again stepB()
If I reverse the order:
@Bean
public Job job() {
return this.jobBuilderFactory.get("job")
.start(stepA())
.on("FAILED").to(stepC())
.from(stepA()).on("*").to(stepB())
.end()
.build();
}
Then I get the following results:
stepA()
is completed successfully then it throws Flow execution ended unexpectedly ... Next state not found in flow=... for state=job.step0 with exit status=COMPLETED
stepA()
fails then step stepC()
is executed >> as expected
The above code was to simplify the explanation, I have attached the example I used. I simulated FAILURE in the first step by throwing an error from FirstItemReader.
Could this be a regression of #3638
Also, what is the difference between, is the latter a valid Flow syntax?:
@Bean
public Job job() {
return this.jobBuilderFactory.get("job")
.start(stepA()).on("*").to(stepB())
.from(stepA()).on("FAILED").to(stepC())
.end()
.build();
}
and:
@Bean
public Job job() {
return this.jobBuilderFactory.get("job")
.start(stepA()).on("*").to(stepB()).end();
.start(stepA()).on("FAILED").to(stepC()).end()
.build();
}
Thank you