Skip to content

Commit 8f41079

Browse files
committed
Perform retryable proceed() call on invocableClone()
Closes gh-35353
1 parent 57fa522 commit 8f41079

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

spring-context/src/main/java/org/springframework/resilience/retry/AbstractRetryInterceptor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import reactor.core.publisher.Mono;
2727
import reactor.util.retry.Retry;
2828

29+
import org.springframework.aop.ProxyMethodInvocation;
2930
import org.springframework.core.ReactiveAdapter;
3031
import org.springframework.core.ReactiveAdapterRegistry;
3132
import org.springframework.core.retry.RetryException;
@@ -103,7 +104,8 @@ public AbstractRetryInterceptor() {
103104
return retryTemplate.execute(new Retryable<>() {
104105
@Override
105106
public @Nullable Object execute() throws Throwable {
106-
return invocation.proceed();
107+
return (invocation instanceof ProxyMethodInvocation pmi ?
108+
pmi.invocableClone().proceed() : invocation.proceed());
107109
}
108110
@Override
109111
public String getName() {

spring-context/src/test/java/org/springframework/resilience/RetryInterceptorTests.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@
1717
package org.springframework.resilience;
1818

1919
import java.io.IOException;
20+
import java.lang.reflect.InvocationTargetException;
2021
import java.lang.reflect.Method;
2122
import java.nio.file.AccessDeniedException;
2223
import java.time.Duration;
2324
import java.util.Properties;
2425
import java.util.concurrent.atomic.AtomicInteger;
2526

27+
import org.aopalliance.intercept.MethodInterceptor;
2628
import org.junit.jupiter.api.Test;
2729

2830
import org.springframework.aop.framework.AopProxyUtils;
2931
import org.springframework.aop.framework.ProxyConfig;
3032
import org.springframework.aop.framework.ProxyFactory;
3133
import org.springframework.aop.framework.autoproxy.AutoProxyUtils;
34+
import org.springframework.aop.interceptor.SimpleTraceInterceptor;
3235
import org.springframework.aop.support.AopUtils;
3336
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
3437
import org.springframework.beans.factory.support.RootBeanDefinition;
@@ -59,7 +62,30 @@ void withSimpleInterceptor() {
5962
pf.setTarget(target);
6063
pf.addAdvice(new SimpleRetryInterceptor(
6164
new MethodRetrySpec((m, t) -> true, 5, Duration.ofMillis(10))));
62-
NonAnnotatedBean proxy = (NonAnnotatedBean) pf.getProxy();
65+
pf.addAdvice(new SimpleTraceInterceptor());
66+
PlainInterface proxy = (PlainInterface) pf.getProxy();
67+
68+
assertThatIOException().isThrownBy(proxy::retryOperation).withMessage("6");
69+
assertThat(target.counter).isEqualTo(6);
70+
}
71+
72+
@Test
73+
void withSimpleInterceptorAndNoTarget() {
74+
NonAnnotatedBean target = new NonAnnotatedBean();
75+
ProxyFactory pf = new ProxyFactory();
76+
pf.addAdvice(new SimpleRetryInterceptor(
77+
new MethodRetrySpec((m, t) -> true, 5, Duration.ofMillis(10))));
78+
pf.addAdvice(new SimpleTraceInterceptor());
79+
pf.addAdvice((MethodInterceptor) invocation -> {
80+
try {
81+
return invocation.getMethod().invoke(target, invocation.getArguments());
82+
}
83+
catch (InvocationTargetException ex) {
84+
throw ex.getTargetException();
85+
}
86+
});
87+
pf.addInterface(PlainInterface.class);
88+
PlainInterface proxy = (PlainInterface) pf.getProxy();
6389

6490
assertThatIOException().isThrownBy(proxy::retryOperation).withMessage("6");
6591
assertThat(target.counter).isEqualTo(6);
@@ -237,7 +263,7 @@ void withEnableAnnotation() throws Exception {
237263
}
238264

239265

240-
static class NonAnnotatedBean {
266+
static class NonAnnotatedBean implements PlainInterface {
241267

242268
int counter = 0;
243269

@@ -248,6 +274,12 @@ public void retryOperation() throws IOException {
248274
}
249275

250276

277+
public interface PlainInterface {
278+
279+
void retryOperation() throws IOException;
280+
}
281+
282+
251283
static class AnnotatedMethodBean {
252284

253285
int counter = 0;

0 commit comments

Comments
 (0)