0

I studied the answer from this question @Recover methods are not triggered with @Retryable

But I can't figure out why recover method does not run in my case.

@Service public MyRetryingService {

    @Scheduled(fixedRate = 10 * 1000)
    @Retryable(backoff = @Backoff(delay = 100, maxDelay = 101), maxAttempts = 3)
    public void transferData() {
        throw new IllegalArgumentException();
    }

    @Recover
    public void recover(IllegalArgumentException exception) {
        System.out.println("Recovering from a service down");
    }
}

I get this exception

org.springframework.retry.ExhaustedRetryException: Cannot locate recovery method; nested exception is java.lang.IllegalArgumentException

What am I missing here?

takendarkk
  • 3,347
  • 8
  • 25
  • 37
Kamal Joshi
  • 498
  • 1
  • 7
  • 19

1 Answers1

1

What version of Spring Framework are you using?

It's a problem that was recently fixed SPR-16196.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • I am using spring boot 1.5.3 which seems to use spring core 4.3.8.RELEASE. Also please note that Retry method is performing retries as it should, but the Recover method is not called after 3 tries. I will try updating to the latest spring boot and see if that improves things. Thank you. – Kamal Joshi Mar 28 '18 at 22:50
  • Updating to the latest version of spring boot 2.0.0.RELEASE resolved my issue although the fix version mentioned in the issue would have been sufficient I think. Thank you. – Kamal Joshi Mar 28 '18 at 22:57
  • The current 1.5.x version (1.5.10) uses SF 4.3.14, which includes the fix [see here](https://github.com/spring-projects/spring-boot/blob/v1.5.10.RELEASE/spring-boot-dependencies/pom.xml#L154). But moving to 2.0 is a good move anyway. – Gary Russell Mar 28 '18 at 23:09