我是 spring 的新手,作为项目实现的一部分,我应该在调用 JPA 存储库的服务方法上添加 spring 重试。代码如下所示
@Retryable(value = {Exception.class},maxAttempts = 1,backoff = @Backoff(300))
public Page<Account> findAllAccounts(AccountSearchRequest account, Pageable pageable) {
try {
return map(accountSearchRepository.findAll(account, pageable));
}catch (Exception e){
System.out.println("SQL EXCEPTION CAUGTH!!!!!!!!!");
}
return null;
}
@Recover
public void recover(Exception e){
System.out.println("!!!!!!!!!!!Failed to get connection!!!!!!");
}
Run Code Online (Sandbox Code Playgroud)
数据库:Postgresql,
应用程序:Java Spring Boot(公开 Rest API 以获取所有帐户)
HikariPool 最大池大小 ** : **1
Hikari 连接超时 ** : **1000
JMeter 用于发送10,000 个API 请求。
问题:我能够看到SQL EXCEPTION CAUGTH!!!!!!!!! 打印,但我认为重试不起作用,因为我没有看到恢复方法的打印。我错过了什么吗?
下面是gradle依赖项
// https://mvnrepository.com/artifact/org.springframework.retry/spring-retry …Run Code Online (Sandbox Code Playgroud)