SpringBoot 中載入resources中資原始檔
阿新 • • 發佈:2019-01-03
SpringBoot 中載入resources中資原始檔
1、目錄結構
2、json內容
{
"A": {
"AA": "AAValue",
"AB": "ABValue"
},
"A": {
"AA": "AAValue",
"AB": "ABValue"
}
}
3、依賴包
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</ artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.3</version>
</dependency>
4、核心程式碼
public static Map< String, LinkedHashMap<String, String>> tbInfoMap = new ConcurrentHashMap();
static {
ObjectMapper objectMapper = new ObjectMapper();
try {
tbInfoMap = objectMapper.readValue(Application.class.getClassLoader().getResourceAsStream("tbInfo.json"), ConcurrentHashMap. class);
} catch (IOException e) {
e.printStackTrace();
}
}