diff --git a/README.md b/README.md index 2c1077e..77564fe 100644 --- a/README.md +++ b/README.md @@ -512,6 +512,35 @@ class Service { } ``` +Version 1.3.2 and later supports matching a paramterized (generic) return type to detect the correct recovery method: + +```java +@Service +class Service { + + @Retryable(RemoteAccessException.class) + public List service1(String str1, String str2) { + // ... do something + } + + @Retryable(RemoteAccessException.class) + public List service2(String str1, String str2) { + // ... do something + } + + @Recover + public List recover1(RemoteAccessException e, String str1, String str2) { + // ... error handling for service1 + } + + @Recover + public List recover2(RemoteAccessException e, String str1, String str2) { + // ... error handling for service2 + } + +} +``` + Version 1.2 introduced the ability to use expressions for certain properties. The following example show how to use expressions this way: diff --git a/src/main/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandler.java b/src/main/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandler.java index 80065af..9a3c8fe 100644 --- a/src/main/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandler.java +++ b/src/main/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandler.java @@ -197,10 +197,12 @@ public class RecoverAnnotationRecoveryHandler implements MethodInvocationReco * deciding a match. * @param methodReturnType * @param failingMethodReturnType - * @return + * @return true if the parameterized return types match. + * @since 1.3.1 */ private boolean isParameterizedTypeAssignable(ParameterizedType methodReturnType, ParameterizedType failingMethodReturnType) { + Type[] methodActualArgs = methodReturnType.getActualTypeArguments(); Type[] failingMethodActualArgs = failingMethodReturnType.getActualTypeArguments(); if (methodActualArgs.length != failingMethodActualArgs.length) { diff --git a/src/test/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandlerTests.java b/src/test/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandlerTests.java index 02c25fd..82d2d62 100644 --- a/src/test/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandlerTests.java +++ b/src/test/java/org/springframework/retry/annotation/RecoverAnnotationRecoveryHandlerTests.java @@ -30,7 +30,9 @@ import org.springframework.retry.ExhaustedRetryException; import org.springframework.util.CollectionUtils; import org.springframework.util.ReflectionUtils; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; /** * @author Dave Syer @@ -501,12 +503,6 @@ public class RecoverAnnotationRecoveryHandlerTests { Collections.singletonMap("bar", Collections.singletonMap((Number) 0.0, "barRecoverNumberValue"))); } - @Recover - public Map>> barRecoverDouble(RuntimeException re, String name) { - return Collections.singletonMap("bar", - Collections.singletonMap("bar", Collections.singletonMap(0.0, "barRecoverDoubleValue"))); - } - } protected static class MultipleQualifyingRecoversNoThrowable {