Reputation: 89
I've been experimenting with the spring-retry project. I have successfully used it's @Retryable features but I am unable to get it to work using a JDK Dynamic Proxy.
I'm using a the following code snippet in my tests.
@Configuration
@EnableRetry
public class TestConfig {
@Bean
public MethodInterceptor retryInterceptor() {
return RetryInterceptorBuilder.stateful().maxAttempts(3).build();
}
}
@Service
public class RetryableServiceImpl implements RetryableService {
private int count = 0;
@Retryable(RuntimeException.class)
@Override
public void service() {
if (count++ < 2) {
throw new RuntimeException("Planned");
}
}
@Override
public int getCount() {
return count;
}
}
@ContextConfiguration(...)
public class RetryableServiceImplTest ... {
@Autowired
private RetryableService retryableService;
@Test
public void test() {
assertTrue(AopUtils.isAopProxy(retryableService));
assertTrue(AopUtils.isJdkDynamicProxy(retryableService));
assertFalse(AopUtils.isCglibProxy(retryableService));
retryableService.service();
assertEquals(3, retryableService.getCount());
}
}
Sample project available here: https://github.com/maddenj-ie/retry.git
So, my questions are
Should this work using either cglib or JDK dynamic proxies?
If so, what is wrong with my setup?
Thanks for the help.
Regards, Joe
Upvotes: 2
Views: 1555
Reputation: 89
After some further investigation, to answer my own questions:
It does work with both proxy mechanisms.
The @Retryable annotation must be applied to the interface instead of the class in order for it to be applied correctly.
Debugging the AnnotationAwareRetryOperationsInterceptor help me understand this.
Upvotes: 3