Spring / Spring Retry Interview Questions
How do you configure Spring Retry using application properties in Spring Boot?
Spring Retry itself does not directly read application.properties — its configuration is annotation or bean-driven. However, Spring Boot's auto-configuration for retry integrates with property placeholders, allowing you to externalize retry parameters using Spring Expression Language (SpEL) references in annotations.
Externalizing retry parameters via properties:
# application.properties retry.maxAttempts=5 retry.delay=2000 retry.multiplier=1.5
@Retryable( retryFor = Exception.class, maxAttemptsExpression = "${retry.maxAttempts}", backoff = @Backoff( delayExpression = "${retry.delay}", multiplierExpression = "${retry.multiplier}" ) ) public void callApi() { ... }
This approach lets you change retry behavior per environment without recompiling. The attributes that accept SpEL expressions are: maxAttemptsExpression, delayExpression, maxDelayExpression, multiplierExpression, and randomExpression.
Note that when using SpEL expressions in annotations, the annotation attributes ending in Expression must be used — not the plain numeric ones. Mixing both (e.g., setting both maxAttempts and maxAttemptsExpression) will result in a compilation or runtime error.
More Related questions...