0

I want the @Recover method to be switched on/off based on a flag in the properties file. How to do that?

Actually, I am not using annotations (@Retryable / @Recover), instead, I am using RetryTemplate.

Solution

I am using this following method as a wrapper method to all the recover calls.

private <T> T genericRecover(RetryContext context) {
    if(this.useRecoverMethod) {
        return null;
    }

    throw new RuntimeException(context.getLastThrowable());
}

Here the useRecoverMethod boolean flag is read from the properties file.

public Resource<Camera> myRetyableMethod(Long cameraId) {

    return retryTemplate.execute(context -> anApiCallMethod(param),
                                    context -> genericRecover(context));
}
Soumitri Pattnaik
  • 3,246
  • 4
  • 24
  • 42

1 Answers1

1

It's not possible.

But, of course, your @Recover method can re-throw the exception (or not) based on the property.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179