前言
项目中有可能涉及到从 yml 或 properties 配置文件加载复杂对象如数组、集合、嵌套对象等。针对这种需求以下举一个例子来实现对嵌套对象(包含集合)的加载。
1.加载目标
{
"clientInfos":[
{
"clientId":"123",
"clientSecret":"veradsfiwee21dw",
"apiLimitSwitch":true,
"ipLimitSwitch":true,
"ipWhiteList":[
"192.168.1.100",
"192.168.1.101"
],
"apiWhiteList":[
"/api/user/list",
"/api/user/detail"
]
},
{
"clientId":"456",
"clientSecret":"cneuave23hjf3io",
"apiLimitSwitch":true,
"ipLimitSwitch":false,
"apiWhiteList":[
"/api/user/list",
"/api/user/detail"
]
}
]
}
2.引入依赖
// gradle
compileOnly "org.springframework.boot:spring-boot-configuration-processor"
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
// maven
<dependency>
<groupId>org