Springboot @retryable not retrying

前端 未结 6 1231
再見小時候
再見小時候 2021-02-19 11:03

The following code is not retrying. What am I missing?

@EnableRetry
@SpringBootApplication
public class App implements CommandLineRunner
{
    .........
    ....         


        
6条回答
  •  无人及你
    2021-02-19 11:42

    It work for return type as well

    @Service
    public class RetryService {
    
    private int count = 0;
    
    // try the method 9 times with 2 seconds delay.
    @Retryable(maxAttempts = 9, value = Exception.class, backoff = @Backoff(delay = 2000))
    public String springReTryTest() throws Exception {
        count++;
        System.out.println("try!");
    
        if (count < 4)
            throw new Exception();
        else
            return "bla";
      }
    
    }
    

提交回复
热议问题