ueditor百度富文字編輯器linux下報錯: class path resource [config.json] cannot be resolved to absolute file path because it does not reside in the file system
阿新 • • 發佈:2018-11-30
具體報錯資訊如下
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包中抓取檔案
具體程式碼修改如下: