Spring / Spring Retry Interview Questions
How does Spring Retry integrate with Spring Batch?
Spring Batch has first-class integration with Spring Retry at the step level. When configuring a Step, you can specify retry behavior on the StepBuilder so that item processing failures trigger automatic retries before the item is sent to the skip list or causes the step to fail.
Step-level retry configuration:
@Bean public Step processStep(JobRepository jobRepository, PlatformTransactionManager txManager, ItemReader<Order> reader, ItemProcessor<Order, Invoice> processor, ItemWriter<Invoice> writer) { return new StepBuilder("processStep", jobRepository) .<Order, Invoice>chunk(10, txManager) .reader(reader) .processor(processor) .writer(writer) .faultTolerant() .retry(TransientDataAccessException.class) .retryLimit(3) .build(); }
Key points about Spring Batch + Spring Retry integration:
.faultTolerant()must be called to enable retry and skip features on the step.- Retry in Spring Batch is stateful: each chunk transaction rolls back on failure, and the failed item is retried in a subsequent transaction.
- You can combine retry and skip: after
retryLimitfailures on one item, it moves to the skip list (if skip is also configured). - Spring Batch uses
RetryTemplateinternally and exposes configuration through the fluent StepBuilder API.
More Related questions...