Springboot @retryable 不重试

新手上路,请多包涵

以下代码不会重试。我错过了什么?

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

    @Retryable()
    ResponseEntity<String> authenticate(RestTemplate restTemplate, HttpEntity<MultiValueMap<String, String>> entity) throws Exception
    {
        System.out.println("try!");
        throw new Exception();
        //return restTemplate.exchange(auth_endpoint, HttpMethod.POST, entity, String.class);
    }

我已将以下内容添加到 pom.xml。

     <dependency>
        <groupId>org.springframework.retry</groupId>
        <artifactId>spring-retry</artifactId>
        <version>1.1.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-aop</artifactId>
    </dependency>

我还尝试为@Retryable 提供不同的参数组合。

 @Retryable(maxAttempts=10,value=Exception.class,backoff=@Backoff(delay = 2000,multiplier=2))

谢谢。

原文由 engg 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 704
1 个回答

在 spring boot 2.0.2 版本中,我观察到 @Retryable 如果您在同一类中有可重试和调用的方法,则无法正常工作。调试时发现切入点没有正确构建。目前,这个问题的解决方法是我们需要在不同的类中编写方法并调用它。

可以在 此处 找到工作示例。

原文由 nkharche 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题