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));
}