添加依赖
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
启动类添加@EnableRetry
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/fbe1d21c9ad6f3a21b0ce7a33a41f7de.png)
重试代码实现
@Slf4j
@Component
public class RetryComponent {
@Retryable(
exclude = NullPointerException.class,
maxAttempts = 5,
backoff = @Backoff(
delay = 1000L,
multiplier = 2
)
)
public boolean sendSmsWithRetry() {
log.info("当前时间 Time={}", LocalDateTime.now());
return SMSUtilsRetry.sendSMS();
}
@Recover
public boolean recover() {
GraceException.display(ResponseStatusEnum.SYSTEM_SMS_FALLBACK_ERROR);
return false;
}
}