ueditor百度富文本编辑器linux下报错: class path resource [config.json] cannot be resolved to absolute file path because it does not reside in the file system

具体报错信息如下

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.<init>(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包中抓取文件

具体代码修改如下:

猜你喜欢

转载自www.cnblogs.com/findtasy/p/10043273.html