【发布时间】:2015-06-26 21:16:23
【问题描述】:
我只是用@Retryable 注解设置了最简单的Spring 应用程序。
@Service
public class MyRestService {
@Autowired
private RestTemplate restTemplate;
@Retryable(Exception.class)
public void runRest() {
ResponseEntity<String> response = restTemplate.getForEntity(
"https://dat.sparkfun.com/streams/dZ4EVmE8yGCRGx5XRX1W.json",
String.class);
}
@Recover
public void recover(Exception e) {
System.out.println("Recover=" + e);
}
}
根据 Spring 文档 (https://github.com/spring-projects/spring-retry),runRest 方法应该运行 3 次,因为它会抛出异常(特别是 org.springframework.web.client.ResourceAccessException)。但是,我没有观察到任何重试。使用 @Retryable 作为参数 ResourceAccessException 没有帮助。
【问题讨论】:
标签: java spring spring-retry