java - How to specify which @Recover method to use for which @Retryable method?
问题描述
So, I've a spring boot app, where in my service class, there are multiple methods that I'm retrying using @Retryable
on them. I've also created their respective recovery methods using @Recover
annotation for them.
Now, a lot of these service methods have the same attributes in method signature; due to which their recover methods end up having the same signature as well.
The problem this is leading to is that the recovery method selection on retry exhaustion is NOT as expected. I'm seeing that the recover method declared under method1 is getting called when method3 fails after all retries.
Is there a way to control the recovery method selection? I've seen the use of RetryTemplate where the RetryCallback and RecoveryCallback are explicitly provided, is that the only way?
Thanks!
Here's what the code looks like:
@Retryable
public boolean method1(String arg1) {
// do something
}
@Recover
public boolean method1Recovery(Exception e, String arg1) {
//do something
}
.
.
.
@Retryable
public boolean method3(String arg1) {
// do something
}
@Recover
public boolean method3Recovery(Exception e, String arg1) {
//do something
}
解决方案
Another way that would probably work is to define and use different exception types, e.g. Method1Exception
… Method3Exception
.
推荐阅读
- java - 无法识别 EditText 变量的值(appcompat 错误)并成功转换编辑文本
- postgresql - 如何修复 postgreSQL 卸载?
- javascript - 防止点击 mouseup
- javascript - 希望重命名 Django Ajax “like”按钮,但不工作
- unit-testing - Vue.js unit:test :有没有办法模拟 Vee-Validate 验证器插件?
- java - 如何将数组的索引打印到单独的 ArrayList 中
- azure - 如何在 Azure Log Analytics Timechart Query 中重命名轴
- loops - 改变
- c++ - 如果语句逻辑不正确
- postgresql - AWS DMS 与 RDS 上的 Postgresql 的连接问题