Springboot @retryable not retrying

前端 未结 6 1200
再見小時候
再見小時候 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:40

    An alternative could be RetryTemplate

    @Bean
        public RetryTemplate retryTemplate() {
            RetryTemplate retryTemplate = new RetryTemplate();
    
            FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();
            fixedBackOffPolicy.setBackOffPeriod(2000l);
            retryTemplate.setBackOffPolicy(fixedBackOffPolicy);
    
            SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
            retryPolicy.setMaxAttempts(2);
            retryTemplate.setRetryPolicy(retryPolicy);
    
            return retryTemplate;
        }
    

    and

    retryTemplate.execute(new RetryCallback() {
        @Override
        public Void doWithRetry(RetryContext arg0) {
            myService.templateRetryService();
            ...
        }
    });
    

    worked out for me

    source

提交回复
热议问题