SpringBoot 读取resource下的文件
1、使用resourceUtil
File file = ResourceUtils.getFile("classpath:config/city.config.json");
2、注解,注入
public abstract class BaseController { @Value("classpath:config/city.config.json") Resource cityConfig; private void setURL(ModelMap root) { String jsonStr = new String(IOUtils.readFully(cityConfig.getInputStream(), -1,true)); JSONObject cityObject = JSON.parseObject(jsonStr); } }