I have integrated a rest template within my spring boot application. The rest template successfully establishes connection and read timeouts. I have also integrated a retry template to retry on these connection and read timeouts. The code for my retry template is below. I am having a problem with my code and cannot figure it out. Any insight would be very helpful.I am having an error with the "callback" it stating it could not be autowired and no beans were found. For 'FAILED' I am getting a cannot resolve symbol.
@Bean
public RetryTemplate retryTemplate(RetryCallback<RetryTemplate, Exception> callback) {
RetryTemplate template = new RetryTemplate();
ExceptionClassifierRetryPolicy retryPolicy = new ExceptionClassifierRetryPolicy();
Map<Class<? extends Throwable>, Boolean> retryableExceptions = new HashMap<Class<? extends Throwable>, Boolean>();
retryableExceptions.put(SocketTimeoutException.class, Boolean.TRUE);
retryableExceptions.put(ConnectionPoolTimeoutException.class, Boolean.TRUE);
retryableExceptions.put(ResourceAccessException.class, Boolean.TRUE);
NeverRetryPolicy doNotRetry = new NeverRetryPolicy();
SimpleRetryPolicy simpleRetryPolicy = new SimpleRetryPolicy(maxAttempts, retryableExceptions);
simpleRetryPolicy.setMaxAttempts(maxAttempts);
FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
backOffPolicy.setBackOffPeriod(backOffPeriod);
template.setRetryPolicy(simpleRetryPolicy);
template.setBackOffPolicy(backOffPolicy);
try {
return template.execute(callback);
} catch (Exception e) {
logger.error("Retry processing failed " + e.getMessage());
return RetryTemplate.FAILED;
}
}