spring boot数组型属性的配置

spring boot普通属性配置非常方便 通过@value(${属性名称})就可以绑定到相关的属性值.但是对于某些比较复杂的对象属性配置且改对象数目不确定时通过固定的属性名配置显然有太复杂,通过list结合map可以较为灵活的对这类对象进行配置范例如下:

@Configuration
@ConfigurationProperties(prefix="com.all.security")
public class ClientConfig {

    private List<Map<String,String>> client;

    public List<Map<String, String>> getClient() {
        return client;
    }

    public void setClient(List<Map<String, String>> client) {
        this.client = client;
    }
}

要获取属性值时通过map

map.get("clientId")
// 对应的key值即可

 

#client config
com.all.security.client[0].clientId=client_1
#
com.all.security.client[0].secret=client_1
com.all.security.client[0].accessTokenValiditySeconds=36000
com.all.security.client[0].resourceIds=dataaccess

com.all.security.client[0].authorizedGrantTypes=client_credentials,refresh_token
com.all.security.client[0].scopes=select



#com.all.security.client[1].clientId]=client_2
#
#com.all.security.client[1].secret=client_2
#com.all.security.client[1].accessTokenValiditySeconds=36000
#com.all.security.client[1].resourceIds=order
#com.all.security.client[1].authorizedGrantTypes=client_credentials,refresh_token
#com.all.security.client[1].scopes=select

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值