我找不到任何关于我需要的行动可能性的信息。我正在使用@Retryable注解和@Recover处理程序方法。像这样的Smth:
@Retryable(value = {Exception.class}, maxAttempts = 5, backoff = @Backoff(delay = 10000))
public void update(Integer id)
{
execute(id);
}
@Recover
public void recover(Exception ex)
{
logger.error("Error when updating object with id {}", id);
}问题是我不知道如何将参数"id“传递给recover()方法。有什么想法吗?提前谢谢。
发布于 2017-10-13 21:24:07
根据Spring Retry documentation,只需对齐@Retryable和@Recover方法之间的参数:
恢复方法的参数可以选择性地包括抛出的异常,也可以选择性地包括传递给原始可重试方法的参数(或者它们的部分列表,只要没有一个被省略)。示例:
@服务类服务{ @Retryable(RemoteAccessException.class) public void服务( String str1,String str2) { // ...做点什么} @Recover public void (RemoteAccessException e,String str1,String str2) { // ...如果需要,使用原始参数进行错误处理}}
所以你可以这样写:
@Retryable(value = {Exception.class}, maxAttempts = 5, backoff = @Backoff(delay = 10000))
public void update(Integer id) {
execute(id);
}
@Recover
public void recover(Exception ex, Integer id){
logger.error("Error when updating object with id {}", id);
}https://stackoverflow.com/questions/46730928
复制相似问题