我有一个项目,而我需要在事务性方法上使用retriable。假设我想要更新一些客户端信息,我需要重试更新2次,直到更新。
我把我的pom依赖
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>在我的@Configuration类中,我有@EnableRetry。在我的@Service类中,我定义了一个方法:
> @Retryable(value = CannotAcquireLockException.class, maxAttempts = 3,
> backoff = @Backoff(delay = 1000,multiplier = 2,maxDelay = 5000))
> @Transactional
> public void updateClient (String info) throws Exception {
> updateClientFromDB(info);
> }我从Junit5测试了我的方法,似乎@Retryable不起作用。我在db中锁定一行,当我运行测试时,它似乎没有重试,它无限循环。
> @ExtendWith(SpringExtension.class)
> @ContextConfiguration(classes = {DSConfig.class })
> @ActiveProfiles({ "test" })
> @Slf4j class Test {
>
> @Test
> void retryTest() {
> String info = "Test";
> updateClient(info); } }发布于 2021-11-19 15:47:03
updateClientFromDB会抛出CannotAcquireLockException吗?
https://stackoverflow.com/questions/70037049
复制相似问题