ArrayList<PatrolOper> patrolOpers = new ArrayList<>();

 String jsonData = null;
File jsonFile = null;
try {
jsonFile = ResourceUtils.getFile("classpath:jsonRequest.json");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
jsonData = FileUtils.readFileToString(jsonFile,"UTF-8");
} catch (IOException e) {
e.printStackTrace();
} Gson gson = new Gson();
PatrolTaskOperRequest bean = gson.fromJson(jsonData, PatrolTaskOperRequest.class); 主要在于,加载了好几次,都发现class下没json文件,后来发现,maven 对resource有过滤。
<!--配置Maven 对resource文件 过滤 -->
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.json</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>

读取resource下文件的更多相关文章

  1. SpringBoot读取Resource下文件的几种方式

    https://www.jianshu.com/p/7d7e5e4e8ae3 最近在项目中涉及到Excle的导入功能,通常是我们定义完模板供用户下载,用户按照模板填写完后上传:这里模板位置resour ...

  2. SpringBoot读取Resource下文件的几种方式(十五)

    需求:提供接口下载resources目录下的模板文件,(或者读取resources下的文件)给后续批量导入数据提供模板文件. 方式一:ClassPathResource //获取模板文件:注意此处需要 ...

  3. Spring Boot 读取 resource 下文件

    支持linux下读取 import org.springframework.core.io.ClassPathResource; public byte[] getCertStream(String ...

  4. SpringBoot读取Linux服务器某路径下文件\读取项目Resource下文件

    // SpringBoot读取Linux服务器某路径下文件 public String messageToRouted() { File file = null; try { file = Resou ...

  5. SpringBoot项目构建成jar运行后,如何正确读取resource下的文件

    SpringBoot项目构建成jar运行后,如何正确读取resource下的文件 不管你使用的是SpringBoot 1.x还是SpringBoot2.x,在开Dev环境中使用eclipse.IEAD ...

  6. maven工程读取resource下配置文件

    maven工程读取resource下配置文件 在maven工程中,我们会将配置文件放到,src/main/resources   下面,例如 我们需要确认resource 下的文件 编译之后存放的位置 ...

  7. Maven项目读取resources下文件的路径问题(getClassLoader的作用)

    读取resources下文件的方法 网上有问答如下:问: new FileInputStream("src/main/resources/all.properties") new ...

  8. 微信退款SpringBoot读取resource下的证书

    微信支付退款接口,需要证书双向验证,测试的时候证书暂时放在resource下,上图 起初MyConfig中我是这样,在本机IDE中运行没有问题 但到Linux服务器的docker中运行就IO异常了,查 ...

  9. Spring项目读取resource下的文件

    目录 一.前提条件 二.使用ClassPathResource类读取 2.1.Controller.service中使用ClassPathResource 2.2.单元测试使用ClassPathRes ...

随机推荐

  1. BZOJ3141 Hnoi2013 游走 【概率DP】【高斯消元】*

    BZOJ3141 Hnoi2013 Description 一个无向连通图,顶点从1编号到N,边从1编号到M. 小Z在该图上进行随机游走,初始时小Z在1号顶点,每一步小Z以相等的概率随机选 择当前顶点 ...

  2. hadoop 的job.setOutputKeyClass和job.setOutputValueClass的几个问题

    昨天写了一个mapreduce函数一直有错误,找不到错误,今天找了一天终于解决了,原来是hadoop 的job.setOutputKeyClass和job.setOutputValueClas设置输出 ...

  3. flask第十四篇——重定向

    我们都知道京东的url是www.jd.com,但是当你输入www.jingdong.com时候,你会发现地址自动跳转到了www.jd.com,这种技术手段就叫做重定向. 重定向分为永久重定向和临时重定 ...

  4. nginx 获取请求头,URL参数

    获取url参数 在 ngx_lua 中访问 Nginx 内置变量 ngx.var.arg_PARAMETER 即可获得GET参数PARAMETER的内容. 在 nginx配置中,通过$arg_PARA ...

  5. Serf 了解

    Introduction to Serf Welcome to the intro guide to Serf! This guide will show you what Serf is, expl ...

  6. 解决Vsphere Client 60天过期问题

  7. centos6.6安装php5.3.3(2015/3/4)

    问题:centos6.6因要升级mysql5.5所以yum重新更新了源,导致按照原来lamp环境安装步骤,安装php时一直找webtitic源,php5.3.24 而且一直无法安装下去 利用yum r ...

  8. MongoDB入门实践

    MongoDB入门实践 简单介绍MongoDB,包括MongoDB的使用场景.和MySQL的对比.安装部署.Java客户端访问及总结 MongoDB? 我们遵循需求驱动技术的原则,通过一个场景来引入M ...

  9. cowboy动态页面的例子

    cowboy的动态页用的是erlydtl,需要先安装erlydtl模板引擎,或者你在dep里面添加 创建工程 rebar-creator create-app testCowboy testCowbo ...

  10. dubbox实现REST服务

    一.dubbox的由来 dubbox是当当网基于dubbo的基础上开发的扩展版,也可以认为是dubbo的升级版,根据当前互联网的应用需求,增加了很多扩展的功能. dubbox并没有发布到maven中央 ...