EnableAspectJAutoProxy features exposeProxy flag (analogous to XML namespace)

Issue: SPR-10454
This commit is contained in:
Juergen Hoeller
2016-06-20 13:50:04 +02:00
parent 01f115869b
commit 8cb9d5ebae
4 changed files with 50 additions and 5 deletions

View File

@@ -20,11 +20,13 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import example.scannable.FooService;
import example.scannable.FooServiceImpl;
import example.scannable.ServiceInvocationCounter;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.junit.Test;
import org.springframework.aop.framework.AopContext;
import org.springframework.aop.support.AopUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
@@ -54,6 +56,14 @@ public class EnableAspectJAutoProxyTests {
assertThat(AopUtils.isCglibProxy(ctx.getBean(FooService.class)), is(true));
}
@Test
public void withExposedProxy() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithExposedProxy.class);
aspectIsApplied(ctx);
assertThat(AopUtils.isJdkDynamicProxy(ctx.getBean(FooService.class)), is(true));
}
private void aspectIsApplied(ApplicationContext ctx) {
FooService fooService = ctx.getBean(FooService.class);
ServiceInvocationCounter counter = ctx.getBean(ServiceInvocationCounter.class);
@@ -101,23 +111,44 @@ public class EnableAspectJAutoProxyTests {
static class ConfigWithJdkProxy {
}
@ComponentScan("example.scannable")
@EnableAspectJAutoProxy(proxyTargetClass = true)
static class ConfigWithCglibProxy {
}
@ComponentScan("example.scannable")
@EnableAspectJAutoProxy(exposeProxy = true)
static class ConfigWithExposedProxy {
@Bean
public FooService fooServiceImpl() {
return new FooServiceImpl() {
@Override
public String foo(int id) {
assertNotNull(AopContext.currentProxy());
return super.foo(id);
}
};
}
}
@Retention(RetentionPolicy.RUNTIME)
public @interface Loggable {
}
@Loggable
public static class SampleDto {
}
public static class SampleInputBean {
}
public static class SampleService {
// Not matched method on {@link LoggingAspect}.
@@ -129,6 +160,7 @@ public class EnableAspectJAutoProxyTests {
}
}
@Aspect
public static class LoggingAspect {