我一直在尝试 spring-retry 项目。我已经成功使用了它的 @Retryable 功能,但我无法使用 JDK 动态代理让它工作。
我在测试中使用了以下代码片段。
@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());
}
}
此处提供示例项目: https ://github.com/maddenj-ie/retry.git
所以,我的问题是
这应该使用 cglib 或 JDK 动态代理吗?
如果是这样,我的设置有什么问题?
谢谢您的帮助。
问候,乔