diff --git a/README.md b/README.md index 730721a..1bdb918 100644 --- a/README.md +++ b/README.md @@ -200,6 +200,10 @@ Foo foo = template.execute(new RetryCallback() { If the business logic does not succeed before the template decides to abort, the client is given the chance to do some alternate processing through the recovery callback. +Version 1.3.3 added the `noRecoveryForNotRetryable` property to the template. +When `true`, the recovery callback is not invoked if the retry policy is configured with a not-retryable exception and one is thrown. +By default, the recovery callback is always called, regardless of whether the exception is retryable or not. + ## Stateless Retry In the simplest case, a retry is just a while loop: the `RetryTemplate` can keep trying @@ -576,6 +580,8 @@ Expressions can contain property placeholders, such as `#{${max.delay}}` or during initialization. There is no root object for the evaluation but they can reference other beans in the context. +Version 1.3.3 added the `rethrow` attribute to `@Retryable`; when `true` any exceptions that are not retryable are thrown unchanged to the caller and the `@Recover` method is not called. + #### Additional Dependencies The declarative approach to applying retry handling by using the `@Retryable` annotation diff --git a/src/main/java/org/springframework/retry/support/RetryTemplate.java b/src/main/java/org/springframework/retry/support/RetryTemplate.java index 0726221..6d213a3 100644 --- a/src/main/java/org/springframework/retry/support/RetryTemplate.java +++ b/src/main/java/org/springframework/retry/support/RetryTemplate.java @@ -127,6 +127,10 @@ public class RetryTemplate implements RetryOperations { } /** + * Set to true to not call the recovery callback (if any) when a not-retryable + * exception is thrown by the target code in + * {@link #execute(RetryCallback, RecoveryCallback)}. By default, the callback is + * invoked when retries are exhausted, or immediately for not-retryable exceptions. * @param noRecoveryForNotRetryable the noRecoveryForNotRetryable to set * @since 1.3.3 */ @@ -542,6 +546,7 @@ public class RetryTemplate implements RetryOperations { if (state != null && !context.hasAttribute(GLOBAL_STATE)) { this.retryContextCache.remove(state.getKey()); } + // TODO: In 2.0 add retryForException() to the interface. if (this.noRecoveryForNotRetryable && retryPolicy instanceof SimpleRetryPolicy && !((SimpleRetryPolicy) retryPolicy).retryForException(context.getLastThrowable())) { throw context.getLastThrowable();