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();
上一篇: servlet实现简单下载(copy)
下一篇: 簡單servlet上傳實例