spring 重试 setRetryableExceptions、setFatalExceptions 不可用

2024-04-16

根据春季批次/重试文档(http://docs.spring.io/spring-batch/reference/html/retry.html http://docs.spring.io/spring-batch/reference/html/retry.html)在第 9.2 节中,当使用 SimpleRetryPolicy 时,可以通过 setRetryableExceptions 或 setFatalExceptions 指定您想要重试或不重试哪些异常。但是,这些方法在 GitHub 的当前版本 (1.0.3) 中并未定义https://github.com/spring-projects/spring-retry/blob/master/src/main/java/org/springframework/retry/RetryPolicy.java https://github.com/spring-projects/spring-retry/blob/master/src/main/java/org/springframework/retry/RetryPolicy.java .

那么,这是一个文档错误吗?如果没有,那么这些方法位于哪里?

从源代码来看,似乎只能通过采用异常映射的构造函数来设置可重试的异常。似乎没有办法定义致命异常。


也许这会有所帮助。您必须创建一个按类类型保存所有可重试异常的映射,并将其添加到策略中。可能与致命异常类似。

Map<Class<? extends Throwable>, Boolean> r = new HashMap<>();
r.put(RetryException.class, true);
SimpleRetryPolicy p = new SimpleRetryPolicy(MAX_RETRIES, r);
RetryTemplate t = new RetryTemplate();
t.setRetryPolicy(p);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

spring 重试 setRetryableExceptions、setFatalExceptions 不可用 的相关文章

随机推荐