1、使用resourceUtil

 

SpringBoot 读取resource下的文件

 

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

  

相关文章:

  • 2022-12-23
  • 2022-01-11
  • 2021-12-29
猜你喜欢
  • 2019-12-12
  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2021-11-27
  • 2022-01-03
  • 2022-12-23
相关资源
相似解决方案