ueditor百度富文本编辑器linux下报错: class path resource [config.json] cannot be resolved to absolute file path ...

具体报错信息如下

java.io.FileNotFoundException: class path resource [config.json] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/home/java/wcq-new-server/wcq/wcq-admin/target/wcq-admin.jar!/BOOT-INF/classes!/config.json

    at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:217)
    at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:180)
    at com.wcgj.wcq.admin.common.ueditor.ConfigManager.initEnv(ConfigManager.java:173)
    at com.wcgj.wcq.admin.common.ueditor.ConfigManager.(ConfigManager.java:46)
    at com.wcgj.wcq.admin.common.ueditor.ConfigManager.getInstance(ConfigManager.java:60)

一番搜索后发现问题所在:是用了 ResourceUtils.getFile("classpath:config.json") ,这个方法只能从类路径下获取文件,无法从jar包中获取,所以打成jar包后发布到linuxs系统,就报错找不到文件了.

解决方案

使用 ClassPathResource classPathResource = new ClassPathResource("config.json"); 来获取文件,这个方法可以直接从jar包中抓取文件

 

具体代码修改如下:

ueditor百度富文本编辑器linux下报错: class path resource [config.json] cannot be resolved to absolute file path ..._第1张图片

 

觉得有用点个赞哦

转载于:https://www.cnblogs.com/findtasy/p/10043273.html

你可能感兴趣的:(json,java)