mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Log RetryException for @Retryable methods
To improve diagnostics, this commit logs a DEBUG message including the RetryException thrown by RetryTemplate when it's used behind the scenes for @Retryable method invocations. Closes gh-35983
This commit is contained in:
+9
-1
@@ -22,6 +22,8 @@ import java.util.concurrent.Future;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -50,6 +52,8 @@ import org.springframework.util.ClassUtils;
|
||||
*/
|
||||
public abstract class AbstractRetryInterceptor implements MethodInterceptor {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(AbstractRetryInterceptor.class);
|
||||
|
||||
/**
|
||||
* Reactive Streams API present on the classpath?
|
||||
*/
|
||||
@@ -102,6 +106,7 @@ public abstract class AbstractRetryInterceptor implements MethodInterceptor {
|
||||
.maxDelay(spec.maxDelay())
|
||||
.build();
|
||||
RetryTemplate retryTemplate = new RetryTemplate(retryPolicy);
|
||||
String methodName = ClassUtils.getQualifiedMethodName(method, (target != null ? target.getClass() : null));
|
||||
|
||||
try {
|
||||
return retryTemplate.execute(new Retryable<@Nullable Object>() {
|
||||
@@ -112,11 +117,14 @@ public abstract class AbstractRetryInterceptor implements MethodInterceptor {
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return ClassUtils.getQualifiedMethodName(method, (target != null ? target.getClass() : null));
|
||||
return methodName;
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (RetryException ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("@Retryable operation '%s' failed".formatted(methodName), ex);
|
||||
}
|
||||
throw ex.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user