spring-retry retryOn
时间: 2023-09-29 14:03:28 浏览: 101
`retryOn` is a method in Spring Retry framework that allows the user to specify the exception types on which the retry should be attempted.
For example, consider the following code block for retrying a specific operation using Spring Retry:
```
@Retryable(maxAttempts = 3, backoff = @Backoff(delay = 1000), retryOn = {IOException.class})
public void retryOperation() throws IOException {
// Perform operation that may throw IOException
}
```
In this example, the `retryOn` attribute specifies that the retry should be attempted only on `IOException` exception. The `maxAttempts` attribute specifies the maximum number of retry attempts and `backoff` attribute specifies the delay between each retry attempt.
If the `retryOperation` method throws an `IOException` exception, Spring Retry will retry the operation up to three times with a delay of 1 second between each attempt. If the operation still fails after three attempts, the exception will be thrown to the caller.
阅读全文