How can I make spring @retryable configurable?
with the release of Spring-retry version 1.2, it's possible. @Retryable can be configured using SPEL.
@Retryable( value = { SomeException.class,AnotherException.class }, maxAttemptsExpression = "#{@myBean.getMyProperties('retryCount')}", backoff = @Backoff(delayExpression = "#{@myBean.getMyProperties('retryInitalInterval')}"))public void doJob(){ //your code here}
For more details refer: https://github.com/spring-projects/spring-retry/blob/master/README.md
If you want to supply a default, and then optionally override it in your application.properties file:
@Retryable(maxAttemptsExpression = "#{${my.max.attempts:10}}")public void myRetryableMethod() { // ...}
As it is explained here:https://stackoverflow.com/a/43144064
Version 1.2 introduces the ability to use expressions for certain properties.
So you need something like this:
@Retryable(maxAttempts = 3, stateful = true, include = ServiceUnavailableException.class, exclude = URISyntaxException.class, backoff = @Backoff(delayExpression = "#{${your.delay}}" , multiplier = 2) )public void testThatService(String serviceAccountId) throws ServiceUnavailableException, URISyntaxException {