0

I'm having a weird problem with @Retryable annotation.

It suppose to be fired only with the defined exception classes on value property:

@Retryable(value = {IllegalArgumentException.class}, maxAttempts = 2, backoff = @Backoff(delay = 50))

But, it's being fired with any exception:

org.springframework.retry.ExhaustedRetryException: Cannot locate recovery method; nested exception is org.springframework.web.client.HttpClientErrorException$Forbidden: 403 : "{"timestamp":"2021-11-13T16:46:32.842+00:00", ---SO ON---

All documents I see, says, only work with exceptions indicated on value property.

Any ideas?

Kind regards

EDITED:

By ask of @Hans-Christian this are the code:

@Retryable(value = {IllegalArgumentException.class}, maxAttempts = 2, backoff = @Backoff(delay = 50))
public ResponseEntity<Object> subscriptionGet(UUID subscriptionId){
    ResponseEntity response = restTemplate.getForEntity(USER_SUBSCRIPTION_GET_ID_URL, SubscriptionResponse.class, subscriptionId);
    return response;
}

@Recover
public ResponseEntity<Object> recoverSubscriptionGet(IllegalArgumentException e, UUID subscriptionId){
    log.error("Unable to reach service: {}", e.getMessage());
    return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE);
}

In case of other kind of Exception, like HttpClientErrorException.Forbidden the retry fires and lost great deal of time, trying to find this Recover

1 Answers1

0

Based on the error message Cannot locate recovery method it looks like you added the annotation @Recover on another method with a different return value.

If that's the case, either align the return value of your @Recover method to be the same as the method with the @Retryable annotation or remove the recover-method.

Example:

  @Retryable(value = {IllegalArgumentException.class}, maxAttempts = 2, backoff = @Backoff(delay = 50))
  private String doSomething() throws Exception {
      // return value is a String
  }

  @Recover
  void recoverSomething(IllegalArgumentException e) {
      // this method does not return a String
  }
Hans-Christian
  • 542
  • 4
  • 6