如何从Rest模板为SocketTimeoutException实现Spring重试
我想在rest模板中出现“SocketTimeoutException”时使用Spring重试功能 但是春天休息的时候,就像下面这样: org.springframework.web.client.ResourceAccessException:I/O错误:读取超时;嵌套异常为java.net.SocketTimeoutException:读取超时 我在重试模板映射中添加了SocketTimeoutException。如何从Rest模板为SocketTimeoutException实现Spring重试,spring,resttemplate,socket-timeout-exception,spring-retry,connect-timeout,Spring,Resttemplate,Socket Timeout Exception,Spring Retry,Connect Timeout,我想在rest模板中出现“SocketTimeoutException”时使用Spring重试功能 但是春天休息的时候,就像下面这样: org.springframework.web.client.ResourceAccessException:I/O错误:读取超时;嵌套异常为java.net.SocketTimeoutException:读取超时 我在重试模板映射中添加了SocketTimeoutException。 Spring retry仅在我在重试模板映射中添加SocketTimeout
Spring retry仅在我在重试模板映射中添加SocketTimeoutException时有效,或者我还需要添加ResourceAccessException。您需要使用设置了
TraverseCaues
选项的自定义SimpleRetryPolicy
。然后,它将检查原因层次结构以查找匹配项,而不仅仅是查看顶级异常
/**
* Create a {@link SimpleRetryPolicy} with the specified number of retry
* attempts. If traverseCauses is true, the exception causes will be traversed until
* a match is found.
*
* @param maxAttempts the maximum number of attempts
* @param retryableExceptions the map of exceptions that are retryable based on the
* map value (true/false).
* @param traverseCauses is this clause traversable
*/
public SimpleRetryPolicy(int maxAttempts, Map<Class<? extends Throwable>, Boolean> retryableExceptions,
boolean traverseCauses) {
this(maxAttempts, retryableExceptions, traverseCauses, false);
}
/**
*创建具有指定重试次数的{@link SimpleRetryPolicy}
*尝试。如果TraverseCaues为true,则将遍历异常原因,直到
*找到匹配项。
*
*@param maxAttempts最大尝试次数
*@param retryableExceptions基于
*映射值(真/假)。
*@param traversecaus此子句是否可遍历
*/
公共SimpleRetryPolicy(int-maxtures,Map)