Spring / Spring Retry Interview Questions
What is the @Retryable annotation and what are its key attributes?
The @Retryable annotation is placed on a Spring-managed bean method to declare that it should be retried automatically when it throws a specified exception. Spring Retry wraps the method in an AOP proxy and applies the configured retry policy transparently to the caller.
Key attributes of @Retryable:
| Attribute | Default | Description |
|---|---|---|
| value / retryFor | Exception.class | Exception types that trigger a retry |
| noRetryFor | – | Exception types that must NOT trigger a retry |
| maxAttempts | 3 | Total number of attempts including the first try |
| backoff | no delay | A nested @Backoff for delay between retries |
| listeners | – | Names of RetryListener beans to notify |
| recover | – | Name of a specific @Recover method to use |
Example:
@Retryable(
retryFor = { HttpServerErrorException.class },
maxAttempts = 4,
backoff = @Backoff(delay = 1000, multiplier = 2)
)
public String callExternalService() {
return restTemplate.getForObject(url, String.class);
}This retries up to 4 times on HttpServerErrorException with an exponential backoff starting at 1 second.
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...
