[英]Nested configuration by yaml - spring boot
下面是我的 yaml 配置。
configuration:
internalUser:
add:
city:
path: path
name: cityName
country:
path: path
name: countryName
replace:
city:
path: path
name: cityName
remove:
city:
path: path
name: cityName
externalUser:
add:
city:
path: path
name: cityName
country:
path: path
name: countryName
replace:
city:
path: path
name: cityName
remove:
city:
path: path
name: cityName
配置類看起來像:
@ConfigurationProperties(prefix = "configuration")
public class Configuration {
private Map<String, Map<String,Map<String>,Address>>> internalUser = new HashMap<>();
//setter and getter
}
Public class Address{
private String path;
private String name;
//setter and getter
}
加載應用程序時它失敗並且無法投射對象。
我的配置有問題嗎? 或者我們可以對這個配置使用嵌套配置嗎? 請幫我配置。
你的地圖太多了。 你只需要兩張地圖。
第一個映射鍵: add, replace, remove
第二個地圖鍵: city
@ConfigurationProperties(prefix = "configuration")
public class Configuration {
private Map<String, Map<String, Address>>> internalUser;
private Map<String, Map<String, Address>>> externalUser;
//setter and getter
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.