Add proxyTargetClass attribute to @EnableRetry
This commit is contained in:
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -39,10 +39,11 @@ import org.springframework.retry.interceptor.NewMethodArgumentsIdentifier;
|
||||
import org.springframework.retry.policy.RetryContextCache;
|
||||
|
||||
/**
|
||||
* Basic configuration for <code>@Retryable</code> 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 <code>@Retryable</code> 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<Class<? extends Annotation>> retryAnnotationTypes) {
|
||||
protected Pointcut buildPointcut(
|
||||
Set<Class<? extends Annotation>> retryAnnotationTypes) {
|
||||
ComposablePointcut result = null;
|
||||
for (Class<? extends Annotation> retryAnnotationType : retryAnnotationTypes) {
|
||||
Pointcut cpc = new AnnotationMatchingPointcut(retryAnnotationType, true);
|
||||
Pointcut cpc = new AnnotationMatchingPointcut(retryAnnotationType,
|
||||
true);
|
||||
Pointcut mpc = AnnotationMatchingPointcut
|
||||
.forMethodAnnotation(retryAnnotationType);
|
||||
if (result == null) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user