@@ -96,6 +96,8 @@ public class RetryTemplate implements RetryOperations {
96
96
97
97
private boolean throwLastExceptionOnExhausted ;
98
98
99
+ private boolean noRecoveryForNotRetryable ;
100
+
99
101
/**
100
102
* Main entry point to configure RetryTemplate using fluent API. See
101
103
* {@link RetryTemplateBuilder} for usage examples and details.
@@ -119,12 +121,19 @@ public static RetryTemplate defaultInstance() {
119
121
120
122
/**
121
123
* @param throwLastExceptionOnExhausted the throwLastExceptionOnExhausted to set
122
- * @since 1.3.3
123
124
*/
124
125
public void setThrowLastExceptionOnExhausted (boolean throwLastExceptionOnExhausted ) {
125
126
this .throwLastExceptionOnExhausted = throwLastExceptionOnExhausted ;
126
127
}
127
128
129
+ /**
130
+ * @param noRecoveryForNotRetryable the noRecoveryForNotRetryable to set
131
+ * @since 1.3.3
132
+ */
133
+ public void setNoRecoveryForNotRetryable (boolean noRecoveryForNotRetryable ) {
134
+ this .noRecoveryForNotRetryable = noRecoveryForNotRetryable ;
135
+ }
136
+
128
137
/**
129
138
* Public setter for the {@link RetryContextCache}.
130
139
* @param retryContextCache the {@link RetryContextCache} to set.
@@ -533,7 +542,7 @@ protected <T> T handleRetryExhausted(RecoveryCallback<T> recoveryCallback, Retry
533
542
if (state != null && !context .hasAttribute (GLOBAL_STATE )) {
534
543
this .retryContextCache .remove (state .getKey ());
535
544
}
536
- if (this .throwLastExceptionOnExhausted && retryPolicy instanceof SimpleRetryPolicy
545
+ if (this .noRecoveryForNotRetryable && retryPolicy instanceof SimpleRetryPolicy
537
546
&& !((SimpleRetryPolicy ) retryPolicy ).retryForException (context .getLastThrowable ())) {
538
547
throw context .getLastThrowable ();
539
548
}
@@ -550,7 +559,7 @@ protected <T> T handleRetryExhausted(RecoveryCallback<T> recoveryCallback, Retry
550
559
}
551
560
552
561
protected <E extends Throwable > void rethrow (RetryContext context , String message ) throws E {
553
- if (this .throwLastExceptionOnExhausted ) {
562
+ if (this .throwLastExceptionOnExhausted || this . noRecoveryForNotRetryable ) {
554
563
@ SuppressWarnings ("unchecked" )
555
564
E rethrow = (E ) context .getLastThrowable ();
556
565
throw rethrow ;
0 commit comments