spring 通过注解实现重试的解决方法
通常来说,我们会用try/catch
,while
循环之类的语法来进行重处理,但是这样的做法缺乏统一性,并且不是很方便,要多写很多代码。
而spring-retry
可以通过注解,在不入侵原有业务逻辑代码的方式下,优雅的实现重处理功能。spring-retry
是spring系列的另一个实用程序模块,可以帮助我们以标准方式处理任何特定操作的重试。在spring-retry
中,所有配置都是基于简单注释的。
1. 使用方法
1. POM依赖
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
2. 在代码中启动@Retryable
@EnableRetry
@SpringBootApplication
public class HelloApplication {
public static void main(String[] args)