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);
  }
}

  

posted on 2020-03-13 22:12  滚动的蛋  阅读(1472)  评论(0编辑  收藏  举报

导航