英文:
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
}
在加载应用程序时,它失败并且无法转换对象。
我的配置有什么问题吗?或者我们可以为这个配置使用嵌套配置吗?
请在配置方面帮助我。
英文:
Below is my yaml configuration.
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
Configuration class look like:
@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
}
While loading the application it is failing and not able to cast the object.
Is there anything is wrong with my configuration? Or can We use the nested configuration for this configuration?
Please help me in the configuration.
答案1
得分: 3
你有一个多余的地图。你只需要两个地图。
第一个地图的键: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
}
英文:
You have one too many maps. You only need two maps.
First map keys: add, replace, remove
Second map keys: city
@ConfigurationProperties(prefix = "configuration")
public class Configuration {
private Map<String, Map<String, Address>>> internalUser;
private Map<String, Map<String, Address>>> externalUser;
//setter and getter
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论