@Retryableアノテーションを使用して最も単純なSpringアプリケーションをセットアップするだけです。
@Service
public class MyRestService {
@Autowired
private RestTemplate restTemplate;
@Retryable(Exception.class)
public void runRest() {
ResponseEntity<String> response = restTemplate.getForEntity(
"https://dat.sparkfun.com/streams/dZ4EVmE8yGCRGx5XRX1W.json",
String.class);
}
@Recover
public void recover(Exception e) {
System.out.println("Recover=" + e);
}
}
Springのドキュメント(https://github.com/spring-projects/spring-retry)によると、メソッドrunRestは例外(特にorg.springframework.web.client.ResourceAccessException)をスローするため、3回実行する必要があります。しかし、私は再試行を観察しません。@RetryableへのResourceAccessExceptionを引数として使用しても役に立ちません。
申し訳ありませんが、非常に簡単な答えです。mainメソッドを使用してクラスで@EnableRetryを指定する必要がありました。
@Configuration
@EnableRetry
public class Application {
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加