I want to implement a Job similar to the following one, using Spring Batch:
Step1 -----> Step2 --> End
^ |
| |
------------
On some condition in Step2, determined by a custom ExitCode of Step2, either Step1 is started again and thus after it, Step2 again, or the processing will end.
What I've imagined is something like this:
return jobBuilderFactory.get("jobName").incrementer(new RunIdIncrementer())
.start(step1()).next(step2())
.on("condition1").end()
.from(step1())
.on("condition2").to(step1()).end().build();
But obviously, after Step1 was processed through the condition2 of Step2, Step2 won't be started again.
How can I implement such a recursive Batch Processing?
EDIT: I managed to get a solution, however, I do not know yet if it's just a dirty one, because it seems to be just to easy:
jobBuilderFactory.get("jobName")
.flow(step1())
.next(step2())
.on("launchStep1Again")
.to(step1())
.from(step2())
.on("endJobExecution")
.end().build().build();
So the simple change from using the Fluent API's .start() method to its .flow() method seems to do the trick.