我在Spring Boot 1.5.9.RELEASE上使用了编译’org.springframework.retry:spring-retry:1.2.2.RELEASE’.
配置为重试我的方法,它运作良好:
@Retryable(value = { IOException.class },maxAttempts = 5,backoff = @Backoff(delay = 500))
public void someMethod(){...}
最佳答案@H_502_12@
通过代码查看org.springframework.retry.support.RetryTemplate执行重试逻辑以重试操作.此模板仅记录以下简单内容:
o.s.retry.support.RetryTemplate : Retry: count=0
o.s.retry.support.RetryTemplate : Checking for rethrow: count=1
o.s.retry.support.RetryTemplate : Retry: count=1
o.s.retry.support.RetryTemplate : Checking for rethrow: count=2
o.s.retry.support.RetryTemplate : Retry: count=2
o.s.retry.support.RetryTemplate : Checking for rethrow: count=3
o.s.retry.support.RetryTemplate : Retry Failed last attempt: count=3
如果要记录特定的异常,可以捕获异常日志并重新抛出.不幸的是,据我所知,没有办法在框架内记录自定义消息.
另一种方法是遮蔽负责调用方法的实际拦截器,如RetryOperationsInterceptor,但不建议这样做.
@H_502_12@