Skip to content

Instantly share code, notes, and snippets.

@mchernyavskaya
Last active July 23, 2017 11:33
Show Gist options
  • Save mchernyavskaya/fbb53c6ec380f59119f7f06f39914f1a to your computer and use it in GitHub Desktop.
Save mchernyavskaya/fbb53c6ec380f59119f7f06f39914f1a to your computer and use it in GitHub Desktop.
Spring Retry - create strategy
/*
We want to retry on IOException only.
Other Exceptions won't be retried.
IOException will be retried three times, counting the initial attempt.
*/
final ExceptionClassifierRetryPolicy exRetryPolicy = new ExceptionClassifierRetryPolicy();
exRetryPolicy.setPolicyMap(new HashMap<Class<? extends Throwable>, RetryPolicy>() {{
put(IOException.class, new SimpleRetryPolicy(3));
put(Exception.class, new NeverRetryPolicy());
}});
retryTemplate.setRetryPolicy(exRetryPolicy);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment