From 4f00bb60d8b389f1b4e90a5162372e76cf93b709 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 23 Aug 2016 10:43:46 +0100 Subject: [PATCH] Add example of @Recover with args --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 9917336..2a5b34d 100644 --- a/README.md +++ b/README.md @@ -262,6 +262,22 @@ The `@EnableRetry` annotation also looks for beans of type `Sleeper` and other s The `@EnableRetry` annotation creates proxies for `@Retryable` beans, and the proxies (so the bean instances in the application) have the `Retryable` interface added to them. This is purely a marker interface, but might be useful for other tools looking to apply retry advice (they should usually not bother if the bean already implements `Retryable`). +Recovery method can be supplied, in case you want to take an alternative code path when the retry is exhausted. Methods should be declared in the same class as the `@Retryable` and marged `@Recover`. The arguments for the recovery method can optionally include the exception that was thrown, and also optionally the arguments passed to the orginal retryable method (or a partial list of them as long as none are omitted). Example: + +```java +@Service +class Service { + @Retryable(RemoteAccessException.class) + public void service(String str1, String str2) { + // ... do something + } + @Recover + public void recover(RemoteAccessException e, String str1, String str2) { + // ... error handling making use of original args if required + } +} +``` + ### XML Configuration Here is an example of declarative iteration using Spring AOP to repeat a service call to a method called `remoteCall` (for more detail on how to configure AOP interceptors see the Spring User Guide):