Support @Recovery method that is not defined in interface

This commit is contained in:
Aaron Lucia
2020-04-07 11:46:22 -04:00
committed by Dave Syer
parent 4fe92bb20f
commit 8f3ceedd29
2 changed files with 40 additions and 1 deletions

View File

@@ -166,7 +166,7 @@ public class RecoverAnnotationRecoveryHandler<T> implements MethodInvocationReco
if (retryable != null) {
this.recoverMethodName = retryable.recover();
}
ReflectionUtils.doWithMethods(failingMethod.getDeclaringClass(), new MethodCallback() {
ReflectionUtils.doWithMethods(target.getClass(), new MethodCallback() {
@Override
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
Recover recover = AnnotationUtils.findAnnotation(method, Recover.class);

View File

@@ -181,6 +181,14 @@ public class EnableRetryTests {
context.close();
}
@Test
public void testInterfaceWithNoRecover() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfiguration.class);
NoRecoverInterface service = context.getBean(NoRecoverInterface.class);
service.service();
assertTrue(service.isRecovered());
}
@Test
public void testImplementation() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfiguration.class);
@@ -351,6 +359,11 @@ public class EnableRetryTests {
return new TheClass();
}
@Bean
public NoRecoverInterface anInterfaceWithNoRecover() {
return new NoRecoverClass();
}
@Bean
public NotAnnotatedInterface notAnnotatedInterface() {
return new RetryableImplementation();
@@ -637,6 +650,32 @@ public class EnableRetryTests {
}
public static interface NoRecoverInterface {
void service();
boolean isRecovered();
}
public static class NoRecoverClass implements NoRecoverInterface {
private boolean recovered;
@Override
@Retryable
public void service() {
throw new RuntimeException("Planned");
}
@Recover
public void recover(Exception e) {
this.recovered = true;
}
@Override
public boolean isRecovered() {
return this.recovered;
}
}
public static interface NotAnnotatedInterface {
void service1();