gpt4 book ai didi

spring - @Retryable 没有被触发

转载 作者:行者123 更新时间:2023-12-02 02:01:55 31 4
gpt4 key购买 nike

我试图总结出最简单的重试场景。执行时重试被忽略。

应用程序.java:

@SpringBootApplication
@EnableRetry
public class Application extends SpringBootServletInitializer {
//...

这是在服务类中:

public Boolean processItem() {
Long id = 999L;
try {
retrieveItemWithRetry(id);
return true;
} catch (NoResultException e) {
return false;
}
}

@Retryable(include=NoResultException.class, backoff = @Backoff(delay = 500, maxDelay = 3000), maxAttempts = 5)
private void retrieveItemWithRetry(Long id) {
retrieveItem(id);
}

private OrderRequest retrieveItem(Long id) {
throw new NoResultException();
}

最佳答案

@Retryable方法的内部调用(在同一个类中)是不可重试的;请参阅my answer here从昨天开始,这解释了原因。

此外,@Retryable 方法必须是公共(public)的。

关于spring - @Retryable 没有被触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41883812/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com