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.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
