gpt4 book ai didi

java - Springboot @retryable 不重试

转载 作者:搜寻专家 更新时间:2023-10-30 21:40:49 25 4
gpt4 key购买 nike

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

@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))

谢谢。

最佳答案

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

可以找到工作示例 here .

关于java - Springboot @retryable 不重试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38212471/

25 4 0
文章推荐: Java 泛型,未绑定(bind)通配符