I'm trying to use Spring Batch 2.2.5 with Java config. Here is the config that I have:
@Configuration
@EnableBatchProcessing
public class JobConfiguration {
@Autowired
private JobBuilderFactory jobBuilder;
@Autowired
private StepBuilderFactory stepBuilder;
@Bean
@Autowired
public Job processDocumentsJob() {
return jobBuilder.get("processDocumentsJob")
.start(procesingStep())
.build();
}
@Bean
@Autowired
public Step procesingStep() {
CompositeItemProcessor<File, DocumentPackageFileMetadata> compositeProcessor = new CompositeItemProcessor<File, DocumentPackageFileMetadata>();
compositeProcessor.setDelegates(Lists.newArrayList(
documentPackageFileValidationProcessor(),
documentMetadataFileTransformer()
));
return stepBuilder.get("procesingStep")
.<File, DocumentPackageFileMetadata>chunk(1)
.reader(documentPackageFileReader())
.processor(compositeProcessor)
.writer(documentMetadataFileMigrator())
.faultTolerant()
.skip(DocumentImportException.class)
.skipLimit(10)
.listener(stepExecutionListener())
.build();
}
....
}
With the config above, if the itemwriter (the bean pointed by documentMetadataFileMigrator) throws 'DocumentImportException', then the exception wont be skipped. Spring Batch will actually retry the same input again. i.e. it will use the same input against 'documentPackageFileValidationProcessor'.
But, if I move the logic inside the itemwriter into an itemprocessor:
@Bean
@Autowired
public Step procesingStep() {
CompositeItemProcessor<File, DocumentPackageFileMetadata> compositeProcessor = new CompositeItemProcessor<File, DocumentPackageFileMetadata>();
compositeProcessor.setDelegates(Lists.newArrayList(
documentPackageFileValidationProcessor(),
documentMetadataFileTransformer(),
documentMetadataFileMigratorAsProcessor() // same as itemwriter, but implemented as itemprocessor
));
return stepBuilder.get("procesingStep")
.<File, DocumentPackageFileMetadata>chunk(1)
.reader(documentPackageFileReader())
.processor(compositeProcessor)
.faultTolerant()
.skip(DocumentImportException.class)
.skipLimit(10)
.listener(stepExecutionListener())
.build();
}
then the exception will be skipped correctly. i.e. Spring Batch will not retry the same item against 'documentPackageFileValidationProcessor'. It will go to the next item to process (the one returned from 'documentPackageFileReader').
Is this a bug on Spring Batch, or is it behaving as expected? If so, can someone point me to the relevant documentation?
Thanks guys, and apology if this is a fundamental question.
Best regards,
Alex