您的位置 首页 java

Springboot中yml配置文件使用Map格式

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;
}  

查看效果

文章来源:智云一二三科技

文章标题:Springboot中yml配置文件使用Map格式

文章地址:https://www.zhihuclub.com/188338.shtml

关于作者: 智云科技

热门文章

网站地图