1、前言
程序打包为jar部署后测试发现资源文件找不到,查看代码发现使用的是ResourceUtils.getFile(“classpath:data/provinceName.json”)获取的资源文件,
打包为jar包后,会出现FileNotFoundException。
本地资源文件路径:
2、解决办法
原来的代码
@GetMapping("/getPath")
public JsonResp getPath() throws Exception {
JsonResp<String> resp = new JsonResp<>(JsonResp.STATE_SUCCESS);
File file = ResourceUtils.getFile("classpath:data/provinceName.json");
String jsonData = jsonRead(file