提交 c5d79773 编写于 作者: J Juergen Hoeller

Added tests for custom qualifier annotations on scoped @Bean methods

Issue: SPR-11116
上级 cb624e25
...@@ -52,6 +52,7 @@ public class BeanMethodQualificationTests { ...@@ -52,6 +52,7 @@ public class BeanMethodQualificationTests {
assertFalse(ctx.getBeanFactory().containsSingleton("testBean1")); assertFalse(ctx.getBeanFactory().containsSingleton("testBean1"));
StandardPojo pojo = ctx.getBean(StandardPojo.class); StandardPojo pojo = ctx.getBean(StandardPojo.class);
assertThat(pojo.testBean.getName(), equalTo("interesting")); assertThat(pojo.testBean.getName(), equalTo("interesting"));
assertThat(pojo.testBean2.getName(), equalTo("boring"));
} }
@Test @Test
...@@ -61,6 +62,7 @@ public class BeanMethodQualificationTests { ...@@ -61,6 +62,7 @@ public class BeanMethodQualificationTests {
assertFalse(ctx.getBeanFactory().containsSingleton("testBean1")); assertFalse(ctx.getBeanFactory().containsSingleton("testBean1"));
StandardPojo pojo = ctx.getBean(StandardPojo.class); StandardPojo pojo = ctx.getBean(StandardPojo.class);
assertThat(pojo.testBean.getName(), equalTo("interesting")); assertThat(pojo.testBean.getName(), equalTo("interesting"));
assertThat(pojo.testBean2.getName(), equalTo("boring"));
} }
@Test @Test
...@@ -70,6 +72,7 @@ public class BeanMethodQualificationTests { ...@@ -70,6 +72,7 @@ public class BeanMethodQualificationTests {
assertTrue(ctx.getBeanFactory().containsSingleton("testBean1")); // a shared scoped proxy assertTrue(ctx.getBeanFactory().containsSingleton("testBean1")); // a shared scoped proxy
StandardPojo pojo = ctx.getBean(StandardPojo.class); StandardPojo pojo = ctx.getBean(StandardPojo.class);
assertThat(pojo.testBean.getName(), equalTo("interesting")); assertThat(pojo.testBean.getName(), equalTo("interesting"));
assertThat(pojo.testBean2.getName(), equalTo("boring"));
} }
@Test @Test
...@@ -99,7 +102,7 @@ public class BeanMethodQualificationTests { ...@@ -99,7 +102,7 @@ public class BeanMethodQualificationTests {
return new TestBean("interesting"); return new TestBean("interesting");
} }
@Bean @Qualifier("boring") @Bean @Boring
public TestBean testBean2() { public TestBean testBean2() {
return new TestBean("boring"); return new TestBean("boring");
} }
...@@ -113,7 +116,7 @@ public class BeanMethodQualificationTests { ...@@ -113,7 +116,7 @@ public class BeanMethodQualificationTests {
return new TestBean("interesting"); return new TestBean("interesting");
} }
@Bean @Qualifier("boring") @Scope("prototype") @Bean @Boring @Scope("prototype")
public TestBean testBean2() { public TestBean testBean2() {
return new TestBean("boring"); return new TestBean("boring");
} }
...@@ -127,7 +130,7 @@ public class BeanMethodQualificationTests { ...@@ -127,7 +130,7 @@ public class BeanMethodQualificationTests {
return new TestBean("interesting"); return new TestBean("interesting");
} }
@Bean @Qualifier("boring") @Scope(value="prototype", proxyMode=ScopedProxyMode.TARGET_CLASS) @Bean @Boring @Scope(value="prototype", proxyMode=ScopedProxyMode.TARGET_CLASS)
public TestBean testBean2() { public TestBean testBean2() {
return new TestBean("boring"); return new TestBean("boring");
} }
...@@ -137,6 +140,13 @@ public class BeanMethodQualificationTests { ...@@ -137,6 +140,13 @@ public class BeanMethodQualificationTests {
static class StandardPojo { static class StandardPojo {
@Autowired @Qualifier("interesting") TestBean testBean; @Autowired @Qualifier("interesting") TestBean testBean;
@Autowired @Boring TestBean testBean2;
}
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
public @interface Boring {
} }
@Configuration @Configuration
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册