【发布时间】:2018-05-13 11:00:20
【问题描述】:
我正在使用 spring-retry(使用 java 8 lambda)来重试失败的 REST 调用。我只想重试那些返回 500 错误的调用。但我无法为此配置 retrytemplate bean。目前的bean简单如下:
@Bean("restRetryTemplate")
public RetryTemplate retryTemplate() {
Map<Class<? extends Throwable>, Boolean> retryableExceptions= Collections.singletonMap(HttpServerErrorException.class,
Boolean.TRUE);
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(3, retryableExceptions);
FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
backOffPolicy.setBackOffPeriod(1500); // 1.5 seconds
RetryTemplate template = new RetryTemplate();
template.setRetryPolicy(retryPolicy);
template.setBackOffPolicy(backOffPolicy);
return template;
}
谁能帮我解决这个问题。提前致谢。
【问题讨论】:
-
你检查过这个 SO 问题吗? stackoverflow.com/questions/27236216/…
标签: java spring spring-boot java-8 spring-retry