I\'m using Spring Batch 3.0.3 configured with annotation to create a batch job that repeats a step an undetermined number of times.
My first step will read into memory a
The way I'd approach this is via the following:
StepExecutionListener
that evaluates if there are more items in the list to process. If so, it returns an ExitStatus
that maps to the same step. If not, it returns an ExitStatus
that maps to end the job or continue the job (based on the rest of the flow).For example:
StepExecutionListener
public class MyListener {
@Autowired
private List myItems;
@AfterStep
public ExitStatus afterStep(StepExecution stepExecution) {
if(myItems.size() > 0) {
return new ExitStatus("CONTINUE");
}
else {
return new ExitStatus("FINISHED");
}
}
}
Job Configuration
...
@Bean
public Step step1() {...}
@Bean
public MyListener listener() {..}
@Bean
public Step step2(MyListener listener) {
return stepBuilder.get("step2")
.tasklet(myTasklet()) // Replace this piece as needed
.listener(listener).build();
}
@Bean
public Job job1(Step step1, Step step2) {
return jobBuilder.get("job1")
.start(step1)
.next(step2).on("CONTINUE").to(step2).on("FINISHED").end()
.build();
}
...
Note I have not tested this code so there may be typos, etc.