From 6b69ad901b539d0292647bb8acd12931b9485b71 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 7 May 2014 05:49:43 -0700 Subject: [PATCH] Add proxyTargetClass attribute to @EnableRetry --- .../retry/annotation/EnableRetry.java | 8 +++++++ .../retry/annotation/RetryConfiguration.java | 22 ++++++++++------- .../retry/annotation/EnableRetryTests.java | 24 ++++++++++++++++--- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/springframework/retry/annotation/EnableRetry.java b/src/main/java/org/springframework/retry/annotation/EnableRetry.java index 77ebd6a..8081eb7 100644 --- a/src/main/java/org/springframework/retry/annotation/EnableRetry.java +++ b/src/main/java/org/springframework/retry/annotation/EnableRetry.java @@ -22,6 +22,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.annotation.Import; /** @@ -36,8 +37,15 @@ import org.springframework.context.annotation.Import; */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) +@EnableAspectJAutoProxy(proxyTargetClass = false) @Import(RetryConfiguration.class) @Documented public @interface EnableRetry { + /** + * Indicate whether subclass-based (CGLIB) proxies are to be created as opposed + * to standard Java interface-based proxies. The default is {@code false}. + */ + boolean proxyTargetClass() default false; + } diff --git a/src/main/java/org/springframework/retry/annotation/RetryConfiguration.java b/src/main/java/org/springframework/retry/annotation/RetryConfiguration.java index 994b059..e389363 100644 --- a/src/main/java/org/springframework/retry/annotation/RetryConfiguration.java +++ b/src/main/java/org/springframework/retry/annotation/RetryConfiguration.java @@ -39,10 +39,11 @@ import org.springframework.retry.interceptor.NewMethodArgumentsIdentifier; import org.springframework.retry.policy.RetryContextCache; /** - * Basic configuration for @Retryable processing. For stateful retry, if - * there is a unique bean elsewhere in the context of type {@link RetryContextCache}, - * {@link MethodArgumentsKeyGenerator} or {@link NewMethodArgumentsIdentifier} it will be - * used by the corresponding retry interceptor (otherwise sensible defaults are adopted). + * Basic configuration for @Retryable processing. For stateful + * retry, if there is a unique bean elsewhere in the context of type + * {@link RetryContextCache}, {@link MethodArgumentsKeyGenerator} or + * {@link NewMethodArgumentsIdentifier} it will be used by the corresponding + * retry interceptor (otherwise sensible defaults are adopted). * * @author Dave Syer * @since 2.0 @@ -79,7 +80,8 @@ public class RetryConfiguration extends AbstractPointcutAdvisor implements } /** - * Set the {@code BeanFactory} to be used when looking up executors by qualifier. + * Set the {@code BeanFactory} to be used when looking up executors by + * qualifier. */ @Override public void setBeanFactory(BeanFactory beanFactory) { @@ -131,13 +133,17 @@ public class RetryConfiguration extends AbstractPointcutAdvisor implements /** * Calculate a pointcut for the given retry annotation types, if any. - * @param retryAnnotationTypes the retry annotation types to introspect + * + * @param retryAnnotationTypes + * the retry annotation types to introspect * @return the applicable Pointcut object, or {@code null} if none */ - protected Pointcut buildPointcut(Set> retryAnnotationTypes) { + protected Pointcut buildPointcut( + Set> retryAnnotationTypes) { ComposablePointcut result = null; for (Class retryAnnotationType : retryAnnotationTypes) { - Pointcut cpc = new AnnotationMatchingPointcut(retryAnnotationType, true); + Pointcut cpc = new AnnotationMatchingPointcut(retryAnnotationType, + true); Pointcut mpc = AnnotationMatchingPointcut .forMethodAnnotation(retryAnnotationType); if (result == null) { diff --git a/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java b/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java index f86185b..a610d0c 100644 --- a/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java +++ b/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java @@ -26,7 +26,6 @@ import org.springframework.aop.support.AopUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.retry.backoff.Sleeper; /** @@ -45,6 +44,15 @@ public class EnableRetryTests { context.close(); } + @Test + public void proxyTargetClass() { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( + TestProxyConfiguration.class); + Service service = context.getBean(Service.class); + assertTrue(AopUtils.isCglibProxy(service)); + context.close(); + } + @Test public void marker() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( @@ -106,9 +114,19 @@ public class EnableRetryTests { context.close(); } + @Configuration + @EnableRetry(proxyTargetClass = true) + protected static class TestProxyConfiguration { + + @Bean + public Service service() { + return new Service(); + } + + } + @Configuration @EnableRetry - @EnableAspectJAutoProxy(proxyTargetClass = true) protected static class TestConfiguration { @Bean @@ -179,7 +197,7 @@ public class EnableRetryTests { public void recover(Throwable cause) { this.cause = cause; } - + public Throwable getCause() { return cause; }