以下代码不会重试。我错过了什么?
@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 许可协议
在 spring boot 2.0.2 版本中,我观察到
@Retryable
如果您在同一类中有可重试和调用的方法,则无法正常工作。调试时发现切入点没有正确构建。目前,这个问题的解决方法是我们需要在不同的类中编写方法并调用它。可以在 此处 找到工作示例。