加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Spring @Retryable – 如何在调用时记录?

发布时间:2020-12-15 01:40:03 所属栏目:大数据 来源:网络整理
导读:我在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 someMetho

我在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(){...}

重试发生时如何输出某些特定消息?

最佳答案
通过代码查看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,但不建议这样做.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读