Retry annotation detected on implementing class

Fixes gh-88, closes gh-90
This commit is contained in:
Tomas Poch
2017-10-06 18:41:42 +02:00
committed by Dave Syer
parent a22ebe7514
commit ea184cb153
2 changed files with 59 additions and 1 deletions

View File

@@ -195,7 +195,12 @@ public class AnnotationAwareRetryOperationsInterceptor implements IntroductionIn
private Retryable findAnnotationOnTarget(Object target, Method method) {
try {
Method targetMethod = target.getClass().getMethod(method.getName(), method.getParameterTypes());
return AnnotationUtils.findAnnotation(targetMethod, Retryable.class);
Retryable retryable = AnnotationUtils.findAnnotation(targetMethod, Retryable.class);
if (retryable == null) {
retryable = AnnotationUtils.findAnnotation(targetMethod.getDeclaringClass(), Retryable.class);
}
return retryable;
}
catch (Exception e) {
return null;

View File

@@ -168,6 +168,17 @@ public class EnableRetryTests {
context.close();
}
@Test
public void testImplementation() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TestConfiguration.class);
NotAnnotatedInterface service = context.getBean(NotAnnotatedInterface.class);
service.service1();
service.service2();
assertEquals(5, service.getCount());
context.close();
}
@Test
public void testExpression() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
@@ -321,6 +332,11 @@ public class EnableRetryTests {
return new TheClass();
}
@Bean
public NotAnnotatedInterface notAnnotatedInterface() {
return new RetryableImplementation();
}
}
protected static class Service {
@@ -538,4 +554,41 @@ public class EnableRetryTests {
}
public static interface NotAnnotatedInterface {
void service1();
void service2();
int getCount();
}
@Retryable
public static class RetryableImplementation implements NotAnnotatedInterface {
private int count = 0;
@Override
public void service1() {
if (count++ < 2) {
throw new RuntimeException("Planned");
}
}
@Override
public void service2() {
if (count++ < 4) {
throw new RuntimeException("Planned");
}
}
@Override
public int getCount() {
return count;
}
}
}