diff options
Diffstat (limited to 'spring-context/src/test/java/org/springframework/context/annotation/EnableAspectJAutoProxyTests.java')
-rw-r--r-- | spring-context/src/test/java/org/springframework/context/annotation/EnableAspectJAutoProxyTests.java | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/spring-context/src/test/java/org/springframework/context/annotation/EnableAspectJAutoProxyTests.java b/spring-context/src/test/java/org/springframework/context/annotation/EnableAspectJAutoProxyTests.java index 9995fc5a..feeee8a8 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/EnableAspectJAutoProxyTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/EnableAspectJAutoProxyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -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); @@ -96,30 +106,49 @@ public class EnableAspectJAutoProxyTests { } - @Configuration @ComponentScan("example.scannable") @EnableAspectJAutoProxy static class ConfigWithJdkProxy { } - @Configuration + @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}. @@ -131,6 +160,7 @@ public class EnableAspectJAutoProxyTests { } } + @Aspect public static class LoggingAspect { |