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 list of items used during the repeating step. I'd like the repeating steps to iterate through this job-scoped list.
How can I configure my job to run the same step x times? I've seen examples in xml of a step specifying the next step to run. I'm thinking I could point two steps to each other in an infinite loop until the list has been iterated. Would this work and is there a way to do it with annotations? Below is my main configuration file with some code that wasn't working.
@ComponentScan(excludeFilters = @Filter(IgnoreDuringScan.class))
@EnableAutoConfiguration
@EnableBatchProcessing
@Loggable
public class BatchCrudConfiguration
{
@Bean
public Job batchCRUDJob(JobBuilderFactory jobBuilderFactory, Step[] processSheetSteps)
{
JobBuilder jobBuilder = jobBuilderFactory.get("batchCRUDJob").incrementer(new RunIdIncrementer());
FlowBuilder<FlowJobBuilder> jobFlowBuilder = jobBuilder.flow(processSheetSteps[0]);
for (int i = 1; i < processSheetSteps.length; i++)
{
jobFlowBuilder = jobFlowBuilder.next(processSheetSteps[i]);
}
return jobFlowBuilder.end().build();
}
@Bean
public Step[] processSheetSteps(
StepBuilderFactory stepBuilderFactory,
RawDataReader[] readers,
DelegatingWriter writer,
DelegatingProcessor processor,
@Value("${batchcrud.chunkSize}") int chunkSize)
{
int numberOfReaders = readers.length;
Step[] steps = new Step[numberOfReaders];
for (int i = 0; i < numberOfReaders; i++)
{
steps[i] = stepBuilderFactory.get("processSheet" + i + "Step").<RawData, DataItem>
chunk(chunkSize).reader(readers[i]).processor(processor).writer(writer).build();
}
return steps;
}