gpt4 book ai didi

java - Spring Retry 中的@Retryable 注解不会触发

转载 作者:行者123 更新时间:2023-11-29 10:10:28 25 4
gpt4 key购买 nike

<分区>

我有一个导致死锁的表更新,我试图让 Spring Retry 在方法获得某种锁定异常时重试。我试过去掉 maxAttempts、value 和 backoff,但它似乎从未捕捉到任何异常。我错过了什么吗?我需要在应用程序文件中声明一个 bean 吗?任何帮助将不胜感激!

应用程序.Java

@SpringBootApplication
@EnableRetry
public class Application extends SpringBootServletInitializer {

详细服务

@Service
public class DetailService {

@Retryable(maxAttempts = 5, value = { LockAcquisitionException.class, ConcurrencyFailureException.class }, backoff = @Backoff(delay = 500, multiplier = 2) )
public void delete(final String detailCode) {
try {
this.delete(this.dao.findByDetailCode(detailCode));
} catch (LockAcquisitionException | ConcurrencyFailureException e) {
LOG.warn("Locking error! Going to retry", e.getMessage());
throw e;
}
}

public void delete(Details detail) {
this.dao.delete(detail);
}

@Retryable(maxAttempts = 5, value = { LockAcquisitionException.class, ConcurrencyFailureException.class }, backoff = @Backoff(delay = 500, multiplier = 2) )
public void delete(final Integer id) {
if (id != null) {
try {
this.delete(this.dao.findOne(id));
} catch (LockAcquisitionException | ConcurrencyFailureException e) {
LOG.warn("Locking error! Going to retry", e.getMessage());
throw e;
}
}
}

编辑

重写了上面的 DetailService 以提供更多细节并添加缺失的方法

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