[英]Spring Retry for Dao Class
I have the below code Spring boot version : 2.3.4我有以下代码 Spring Boot 版本:2.3.4
@Repository
class Dbrepository
{
public void performCall() {
simpleJdbcCall = new
SimpleJdbcCall(jdbcTemplate)
.withProcedureName("read_actor")
//.....
simpleJdbcCall.execute(...) ;
}
}
I want to retry the performCall() atleast 3 times at interval of 1 min between each call.我想在每次调用之间以 1 分钟的间隔重试 performCall() 至少 3 次。 How can i achieve this?
我怎样才能做到这一点? I am thinking of using Spring Retry ?Is this the best approach?
我正在考虑使用 Spring Retry ?这是最好的方法吗?
You can achieve it by adding spring-retry您可以通过添加 spring-retry 来实现它
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
Add @EnableRetry
in your main application在主应用程序中添加
@EnableRetry
@Retryable(maxAttempts=3,backoff=@Backoff(delay = 10000))
public void performCall() {
simpleJdbcCall = new
SimpleJdbcCall(jdbcTemplate)
.withProcedureName("read_actor")
//.....
simpleJdbcCall.execute(...) ;
}
Hope useful希望有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.