yml格式配置文件
下面格式 数据定义 了2个App项目信息 ,key值分别为app1、app2。
demo:
client:
app1:
key: app001
secret: fcd64cea96f7f
url:
app2:
key: app002
secret: a7a9bfd47c1adfa
url:
定义配置文件类
注意下面代码中的demo和client,demo为前缀,client为map数据根节点。该map有2个key,
每个key对应的对象为一个AppItem对象。
@Configuration
@ConfigurationProperties(prefix = "demo")
@Setter
@Getter
public class YmlMapConfig {
Map<String, AppItem> client;
public AppItem getByKey(String key){
return client.get(key);
}
}
@Getter
@Setter
public class AppItem {
private String key;
private String secret;
private String url;
}
查看效果
