Skip to content

Commit 2a6c642

Browse files
committed
Added tests for custom qualifier annotations on scoped @bean methods
Issue: SPR-11116 (cherry picked from commit c5d7977)
1 parent 126116e commit 2a6c642

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

spring-context/src/test/java/org/springframework/context/annotation/configuration/BeanMethodQualificationTests.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public void testStandard() {
5151
assertFalse(ctx.getBeanFactory().containsSingleton("testBean1"));
5252
StandardPojo pojo = ctx.getBean(StandardPojo.class);
5353
assertThat(pojo.testBean.getName(), equalTo("interesting"));
54+
assertThat(pojo.testBean2.getName(), equalTo("boring"));
5455
}
5556

5657
@Test
@@ -60,6 +61,7 @@ public void testScoped() {
6061
assertFalse(ctx.getBeanFactory().containsSingleton("testBean1"));
6162
StandardPojo pojo = ctx.getBean(StandardPojo.class);
6263
assertThat(pojo.testBean.getName(), equalTo("interesting"));
64+
assertThat(pojo.testBean2.getName(), equalTo("boring"));
6365
}
6466

6567
@Test
@@ -69,6 +71,7 @@ public void testScopedProxy() {
6971
assertTrue(ctx.getBeanFactory().containsSingleton("testBean1")); // a shared scoped proxy
7072
StandardPojo pojo = ctx.getBean(StandardPojo.class);
7173
assertThat(pojo.testBean.getName(), equalTo("interesting"));
74+
assertThat(pojo.testBean2.getName(), equalTo("boring"));
7275
}
7376

7477
@Test
@@ -89,7 +92,7 @@ public TestBean testBean1() {
8992
return new TestBean("interesting");
9093
}
9194

92-
@Bean @Qualifier("boring")
95+
@Bean @Boring
9396
public TestBean testBean2() {
9497
return new TestBean("boring");
9598
}
@@ -103,7 +106,7 @@ public TestBean testBean1() {
103106
return new TestBean("interesting");
104107
}
105108

106-
@Bean @Qualifier("boring") @Scope("prototype")
109+
@Bean @Boring @Scope("prototype")
107110
public TestBean testBean2() {
108111
return new TestBean("boring");
109112
}
@@ -117,7 +120,7 @@ public TestBean testBean1() {
117120
return new TestBean("interesting");
118121
}
119122

120-
@Bean @Qualifier("boring") @Scope(value="prototype", proxyMode=ScopedProxyMode.TARGET_CLASS)
123+
@Bean @Boring @Scope(value="prototype", proxyMode=ScopedProxyMode.TARGET_CLASS)
121124
public TestBean testBean2() {
122125
return new TestBean("boring");
123126
}
@@ -127,6 +130,13 @@ public TestBean testBean2() {
127130
static class StandardPojo {
128131

129132
@Autowired @Qualifier("interesting") TestBean testBean;
133+
134+
@Autowired @Boring TestBean testBean2;
135+
}
136+
137+
@Qualifier
138+
@Retention(RetentionPolicy.RUNTIME)
139+
public @interface Boring {
130140
}
131141

132142
@Configuration

0 commit comments

Comments
 (0)