微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我在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,但不建议这样做.

原文地址:https://www.jb51.cc/spring/431701.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐