Skip to content

Commit c5d7977

Browse files
committed
Added tests for custom qualifier annotations on scoped @bean methods
Issue: SPR-11116
1 parent cb624e2 commit c5d7977

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
@@ -52,6 +52,7 @@ public void testStandard() {
5252
assertFalse(ctx.getBeanFactory().containsSingleton("testBean1"));
5353
StandardPojo pojo = ctx.getBean(StandardPojo.class);
5454
assertThat(pojo.testBean.getName(), equalTo("interesting"));
55+
assertThat(pojo.testBean2.getName(), equalTo("boring"));
5556
}
5657

5758
@Test
@@ -61,6 +62,7 @@ public void testScoped() {
6162
assertFalse(ctx.getBeanFactory().containsSingleton("testBean1"));
6263
StandardPojo pojo = ctx.getBean(StandardPojo.class);
6364
assertThat(pojo.testBean.getName(), equalTo("interesting"));
65+
assertThat(pojo.testBean2.getName(), equalTo("boring"));
6466
}
6567

6668
@Test
@@ -70,6 +72,7 @@ public void testScopedProxy() {
7072
assertTrue(ctx.getBeanFactory().containsSingleton("testBean1")); // a shared scoped proxy
7173
StandardPojo pojo = ctx.getBean(StandardPojo.class);
7274
assertThat(pojo.testBean.getName(), equalTo("interesting"));
75+
assertThat(pojo.testBean2.getName(), equalTo("boring"));
7376
}
7477

7578
@Test
@@ -99,7 +102,7 @@ public TestBean testBean1() {
99102
return new TestBean("interesting");
100103
}
101104

102-
@Bean @Qualifier("boring")
105+
@Bean @Boring
103106
public TestBean testBean2() {
104107
return new TestBean("boring");
105108
}
@@ -113,7 +116,7 @@ public TestBean testBean1() {
113116
return new TestBean("interesting");
114117
}
115118

116-
@Bean @Qualifier("boring") @Scope("prototype")
119+
@Bean @Boring @Scope("prototype")
117120
public TestBean testBean2() {
118121
return new TestBean("boring");
119122
}
@@ -127,7 +130,7 @@ public TestBean testBean1() {
127130
return new TestBean("interesting");
128131
}
129132

130-
@Bean @Qualifier("boring") @Scope(value="prototype", proxyMode=ScopedProxyMode.TARGET_CLASS)
133+
@Bean @Boring @Scope(value="prototype", proxyMode=ScopedProxyMode.TARGET_CLASS)
131134
public TestBean testBean2() {
132135
return new TestBean("boring");
133136
}
@@ -137,6 +140,13 @@ public TestBean testBean2() {
137140
static class StandardPojo {
138141

139142
@Autowired @Qualifier("interesting") TestBean testBean;
143+
144+
@Autowired @Boring TestBean testBean2;
145+
}
146+
147+
@Qualifier
148+
@Retention(RetentionPolicy.RUNTIME)
149+
public @interface Boring {
140150
}
141151

142152
@Configuration

0 commit comments

Comments
 (0)