Spring重试功能

坐标

    
      org.springframework.retry
      spring-retry
    

启动类加:

@EnableRetry

重试注解

@Retryable 

就这么简单。实例代码

@EnableRetry
@SpringBootApplication
public class RetryApplication {

    public static void main(String[] args) {
        SpringApplication.run(RetryApplication.class, args);
    }
}


@Slf4j
@Service
public class RetryService{
    @Retryable(value = Exception.class, backoff = @Backoff(delay = 1000L),maxAttempts = 5)
    public void retryMethod()  throws Exception{
  
            throw new Exception(e);  
    }
}

 

你可能感兴趣的:(java)