根据第 9.2 节中的 spring 批处理/重试文档 (http://docs.spring.io/spring-batch/reference/html/retry.html),在使用 SimpleRetryPolicy 时,可以通过 setRetryableExceptions 或 setFatalExceptions 指定您希望重试或不重试哪些异常。但是,这些方法未在 GitHub 的当前版本 (1.0.3) 中定义 https://github.com/spring-projects/spring-retry/blob/master/src/main/java/org/springframework/retry/RetryPolicy.java .
那么,这是文档错误吗?如果不是,那么这些方法位于何处?
从源代码来看,似乎只有可重试的异常可以通过采用异常 Map 的构造函数来设置。似乎没有办法定义致命异常。
最佳答案
也许这会有所帮助。您必须创建一个按类类型保存所有可重试异常的映射,并将其添加到策略中。可能与致命异常类似。
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);
关于java - spring retry setRetryableExceptions, setFatalExceptions 不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23094282/