Browse Source
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3378 50f2f4bb-b051-0410-bef5-90022cba6387pull/1/head
1 changed files with 52 additions and 0 deletions
@ -0,0 +1,52 @@ |
|||||||
|
package org.springframework.context.annotation.configuration; |
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo; |
||||||
|
import static org.junit.Assert.assertThat; |
||||||
|
|
||||||
|
import org.junit.Test; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.beans.factory.annotation.Qualifier; |
||||||
|
import org.springframework.context.ApplicationContext; |
||||||
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
||||||
|
import org.springframework.context.annotation.Bean; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import test.beans.TestBean; |
||||||
|
|
||||||
|
/** |
||||||
|
* Tests proving that @Qualifier annotations work when used |
||||||
|
* with @Configuration classes on @Bean methods. |
||||||
|
* |
||||||
|
* @author Chris Beams |
||||||
|
*/ |
||||||
|
public class BeanMethodQualificationTests { |
||||||
|
|
||||||
|
@Test |
||||||
|
public void test() { |
||||||
|
ApplicationContext ctx = |
||||||
|
new AnnotationConfigApplicationContext(Config.class, Pojo.class); |
||||||
|
Pojo pojo = ctx.getBean(Pojo.class); |
||||||
|
assertThat(pojo.testBean.getName(), equalTo("interesting")); |
||||||
|
} |
||||||
|
|
||||||
|
@Configuration |
||||||
|
static class Config { |
||||||
|
@Bean |
||||||
|
@Qualifier("interesting") |
||||||
|
public TestBean testBean1() { |
||||||
|
return new TestBean("interesting"); |
||||||
|
} |
||||||
|
|
||||||
|
@Bean |
||||||
|
@Qualifier("boring") |
||||||
|
public TestBean testBean2() { |
||||||
|
return new TestBean("boring"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Component |
||||||
|
static class Pojo { |
||||||
|
@Autowired @Qualifier("interesting") TestBean testBean; |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue