繁体   English   中英

如何通过 map <string,map<string,integer> &gt; 使用 application.properties </string,map<string,integer>

[英]How to pass a map<String,Map<String,Integer>> with application.properties

当我在 application.properties 中时:

config.map-of-map.Key1.Key2=111

这不能与变量匹配:

Map<String, Map<String, Integer>> mapOfMap;

class 的一部分是什么

@ConfigurationProperties(prefix = "config")
public MyClass getMyClass() {
    return new MyClass();
}

当我想从此 map 读取数据时,我读取 String 而不是 Integer 并得到异常:

Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

有什么方法可以强制它到 Integer 吗?

我不知道为什么这个问题有如此多的反对票。 但我需要做的只是升级 spring 引导版本。

我使用的是 2.1.1.RELEASE 版本,但使用 2.2.1.RELEASE 版本它也可以解析 map 中的 Integer。 然后我就按照这个例子进行嵌套 map 映射

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM