Avoid JDK proxy against CGLIB Factory interface and assert required type when resolving dependency

Issue: SPR-14478
This commit is contained in:
Juergen Hoeller
2016-07-20 18:05:51 +02:00
parent 938b56c0fe
commit 0e3f0bd9d0
5 changed files with 82 additions and 34 deletions

View File

@@ -26,6 +26,7 @@ import java.util.concurrent.Executor;
import java.util.concurrent.Future;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.aop.Advisor;
import org.springframework.aop.framework.Advised;
@@ -37,6 +38,7 @@ import org.springframework.context.annotation.AdviceMode;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.Ordered;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.util.ReflectionUtils;
@@ -67,6 +69,18 @@ public class EnableAsyncTests {
asyncBean.work();
}
@Test
public void proxyingOccursWithMockitoStub() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(AsyncConfigWithMockito.class, AsyncBeanUser.class);
ctx.refresh();
AsyncBeanUser asyncBeanUser = ctx.getBean(AsyncBeanUser.class);
AsyncBean asyncBean = asyncBeanUser.getAsyncBean();
assertThat(AopUtils.isAopProxy(asyncBean), is(true));
asyncBean.work();
}
@Test
public void withAsyncBeanWithExecutorQualifiedByName() throws ExecutionException, InterruptedException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -200,6 +214,20 @@ public class EnableAsyncTests {
}
static class AsyncBeanUser {
private final AsyncBean asyncBean;
public AsyncBeanUser(AsyncBean asyncBean) {
this.asyncBean = asyncBean;
}
public AsyncBean getAsyncBean() {
return asyncBean;
}
}
@EnableAsync(annotation = CustomAsync.class)
static class CustomAsyncAnnotationConfig {
}
@@ -252,6 +280,17 @@ public class EnableAsyncTests {
}
@Configuration
@EnableAsync
static class AsyncConfigWithMockito {
@Bean @Lazy
public AsyncBean asyncBean() {
return Mockito.mock(AsyncBean.class);
}
}
@Configuration
@EnableAsync
static class CustomExecutorAsyncConfig implements AsyncConfigurer {