Support @Recovery method that is not defined in interface
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user