SpringBoot注入Map
写点笔记
共 1780字,需浏览 4分钟
·
2021-07-17 23:34
public class MyBean {
private String name;
private String config;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getConfig() {
return config;
}
public void setConfig(String config) {
this.config = config;
}
public String toString() {
return "MyBean{" +
"name='" + name + '\'' +
", config='" + config + '\'' +
'}';
}
}
"scaffold.tian") (prefix =
public class MyConfig {
private Map, MyBean> client;
public MyConfig() {
}
public Map, MyBean> getClient() {
return client;
}
public void setClient(Map, MyBean> client) {
this.client = client;
}
public String toString() {
return "MyConfig{" +
"client=" + client +
'}';
}
}
配置文件
scaffold.tian.client.name.config=tianjingle
scaffold.tian.client.wang.config=wang
scaffold.tian.client.li.config=li
@Autowired
private MyConfig myConfig;
System.out.println(myConfig.toString());
当我们将需要的基础信息配置管理起来了之后,我们就可以随意的生产不同策略的上层业务类了。是不是感觉这种姿势优点帅?好了,本次文章就到这里!
文章首页图片来自:搜狗百科-周冬雨 https://baike.sogou.com/v39745781.htm
晚安~
评论