我有以下配置类:
@Configuration
public class MyAppConfig {
@Value("${retry.backoff}")
private String retryBackoff;
@Bean
public RetryTemplate retryTemplate() {
RetryTemplate retryTemplate = new RetryTemplate();
FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();
fixedBackOffPolicy.setBackOffPeriod(Long.parseLong(retryBackoff));
retryTemplate.setBackOffPolicy(fixedBackOffPolicy);
retryTemplate.setRetryPolicy(new CustomRetryPolicy());
return retryTemplate;
}
}
下面是我为自定义重试策略创建的组件。此策略的目的是改进它,使其仅在发生某些HttpClientErrorExceptions时重试。
@Component
public class CustomRetryPolicy extends ExceptionClassifierRetryPolicy {
public void CustomRetryPolicy() {
final SimpleRetryPolicy simpleRetryPolicy = new SimpleRetryPolicy();
simpleRetryPolicy.setMaxAttempts(5);
this.setExceptionClassifier(new Classifier<Throwable, RetryPolicy>() {
@Override
public RetryPolicy classify(Throwable classifiable) {
if (classifiable instanceof HttpClientErrorException) {
return simpleRetryPolicy;
}
return simpleRetryPolicy;
}
});
}
}
此问题没有错误日志,并且不会重试。我怎样才能解决这个问题?