欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Spring注解@Qualifier用法

程序员文章站 2022-03-03 12:40:24
...
@Data
@Builder
public class HouseInfo {

    private long id;

    private String one;

    private String two;

    private String three;

    public HouseInfo(long id, String one, String two, String three) {
        this.id = id;
        this.one = one;
        this.two = two;
        this.three = three;
    }
}
@Configuration
public class BeanConfiguration {
    @Bean("house1")
    @Qualifier("good")
    public HouseInfo houseInfo1() {
        return HouseInfo.builder().one("good").build();
    }

    @Bean("house2")
    @Qualifier("bad")
    public HouseInfo houseInfo2() {
        return HouseInfo.builder().one("bad").build();
    }

    @Bean("house3")
    @Qualifier("bad")
    public HouseInfo houseInfo3() {
        return HouseInfo.builder().one("bad").build();
    }
}
    @Autowired
    private List<HouseInfo> houseAll = Collections.emptyList();

    @Autowired
    @Qualifier("good")
    private List<HouseInfo> goodHouse = Collections.emptyList();

    @Autowired
    @Qualifier("bad")
    private List<HouseInfo> badHouse = Collections.emptyList();

 

相关标签: Spring基础