Fixed detection of qualifier annotations on scoped-proxy factory methods
Issue: SPR-11116
This commit is contained in:
@@ -20,7 +20,6 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -28,7 +27,10 @@ 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.context.annotation.Scope;
|
||||
import org.springframework.context.annotation.ScopedProxyMode;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
@@ -51,6 +53,24 @@ public class BeanMethodQualificationTests {
|
||||
assertThat(pojo.testBean.getName(), equalTo("interesting"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScoped() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(ScopedConfig.class, StandardPojo.class);
|
||||
assertFalse(ctx.getBeanFactory().containsSingleton("testBean1"));
|
||||
StandardPojo pojo = ctx.getBean(StandardPojo.class);
|
||||
assertThat(pojo.testBean.getName(), equalTo("interesting"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScopedProxy() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(ScopedProxyConfig.class, StandardPojo.class);
|
||||
assertTrue(ctx.getBeanFactory().containsSingleton("testBean1")); // a shared scoped proxy
|
||||
StandardPojo pojo = ctx.getBean(StandardPojo.class);
|
||||
assertThat(pojo.testBean.getName(), equalTo("interesting"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustom() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
@@ -63,7 +83,8 @@ public class BeanMethodQualificationTests {
|
||||
|
||||
@Configuration
|
||||
static class StandardConfig {
|
||||
@Bean @Lazy @Qualifier("interesting")
|
||||
|
||||
@Bean @Qualifier("interesting") @Lazy
|
||||
public TestBean testBean1() {
|
||||
return new TestBean("interesting");
|
||||
}
|
||||
@@ -74,13 +95,43 @@ public class BeanMethodQualificationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class ScopedConfig {
|
||||
|
||||
@Bean @Qualifier("interesting") @Scope("prototype")
|
||||
public TestBean testBean1() {
|
||||
return new TestBean("interesting");
|
||||
}
|
||||
|
||||
@Bean @Qualifier("boring") @Scope("prototype")
|
||||
public TestBean testBean2() {
|
||||
return new TestBean("boring");
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class ScopedProxyConfig {
|
||||
|
||||
@Bean @Qualifier("interesting") @Scope(value="prototype", proxyMode=ScopedProxyMode.TARGET_CLASS)
|
||||
public TestBean testBean1() {
|
||||
return new TestBean("interesting");
|
||||
}
|
||||
|
||||
@Bean @Qualifier("boring") @Scope(value="prototype", proxyMode=ScopedProxyMode.TARGET_CLASS)
|
||||
public TestBean testBean2() {
|
||||
return new TestBean("boring");
|
||||
}
|
||||
}
|
||||
|
||||
@Component @Lazy
|
||||
static class StandardPojo {
|
||||
|
||||
@Autowired @Qualifier("interesting") TestBean testBean;
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class CustomConfig {
|
||||
|
||||
@InterestingBean
|
||||
public TestBean testBean1() {
|
||||
return new TestBean("interesting");
|
||||
@@ -94,6 +145,7 @@ public class BeanMethodQualificationTests {
|
||||
|
||||
@InterestingPojo
|
||||
static class CustomPojo {
|
||||
|
||||
@InterestingNeed TestBean testBean;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user