Issue with @Retryable(retryFor)
not working as expected after upgrading Spring Boot
#473
Replies: 3 comments 2 replies
-
Any chances that you can share the whole simple project to reproduce? |
Beta Was this translation helpful? Give feedback.
-
Thank you for your response. In my case, the issue wasn’t related to the version after all. Instead, I discovered that when an exception occurs in a method annotated with For example, even with the following setup: @Retryable(retryFor = TokenExpiredException.class) I observed that the Is this expected behavior? Should the Here is a simplified version of my RetryListenerImpl class: import org.springframework.context.annotation.Configuration;
import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext;
import org.springframework.retry.RetryListener;
@Configuration
public class RetryListenerImpl implements RetryListener {
@Override
public <T, E extends Throwable> void onError(
RetryContext context, RetryCallback<T, E> callback, Throwable throwable) {
// Simplified: No business logic here
}
} Looking forward to your clarification on this. Thank you! |
Beta Was this translation helpful? Give feedback.
-
Behavior of @Retryable(retryFor = TokenExpiredException.class)
Is this the intended behavior? If so, I am considering not including retry logic inside the onError method. |
Beta Was this translation helpful? Give feedback.
-
Description
I recently upgraded my Spring Boot project from 2.7.0 to 3.3.2, and I encountered an issue with the
@Retryable
annotation.I want the method to retry only when a specific exception (
TokenExpiredException.class
) is thrown.However, the method retries on all exceptions, not just the specified one.
My setup
Spring Boot version
:3.3.2
(previously2.7.0
, where the retry mechanism worked fine)Spring Retry version
:2.0.6
(previously2.0.0
, where everything worked correctly)Java version
:17
TokenExpiredException
: This is a custom exception in my application.I've tried both the
@Retryable(retryFor = TokenExpiredException.class)
annotation and a RetryTemplate configuration, but the retry mechanism still occurs for all exceptions, not just the one I want to retry (TokenExpiredException.class
).Here is a simplified version of my code (rewritten as a sample):
RetryConfig (with RetryTemplate)
RetryListenerImpl
Service
Expected behavior
The method should retry only when
TokenExpiredException
is thrown, not for any other exceptions.Actual behavior
The method retries for all exceptions, even those that are not
TokenExpiredException
.Additional context
TokenExpiredException
is a custom exception in my application.2.7.0
with Spring Retry2.0.0
.3.3.2
and Spring Retry2.0.6
, this issue appeared.Steps to reproduce
@Retryable(retryFor = TokenExpiredException.class)
in Spring Boot3.3.2
.TokenExpiredException
in the method.I would appreciate it if you could review the issue and provide feedback or suggestions.
Beta Was this translation helpful? Give feedback.
All reactions