zoukankan      html  css  js  c++  java
  • springboot使用jar包方式启动,找不到resources目录中的配置文件(运行时)FileNotFoundException

    将springboot项目打包成jar包,使用 java -jar jar包进行启动,富文本框使用ckeditor+ckfinder;

    因为ckfinder自定义配置文件了,上传图片时出现了异常

    DefaultResourceLoader loader = new DefaultResourceLoader();
                String absolutePath = loader.getResource(this.xmlFilePath).getFile().getAbsolutePath();

    抛出异常:

    java.io.FileNotFoundException: class path resource [ckfinder-config.xml] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/E:/Development/VCS/GIT/dmahzForum/dmahzForum/target/dmahz-forum-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/ckfinder-config.xml
            at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:217)
            at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:131)
            at cn.dmahz.config.CKFinderConfiguration.checkIfReloadConfig(CKFinderConfiguration.java:197)
            at com.ckfinder.connector.configuration.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:59)
            at com.ckfinder.connector.configuration.ConfigurationPathBuilder.getBaseDir(ConfigurationPathBuilder.java:55)
            at com.ckfinder.connector.configuration.ConfigurationFactory.getBaseFolder(ConfigurationFactory.java:189)
            at com.ckfinder.connector.configuration.ConfigurationFactory.updateResourceTypesPaths(ConfigurationFactory.java:151)

    ,测试了好几种方法,结果是只能通过getInputStream()流的方式获取文件内容,否则就会抛出上面所述的异常;;;

    更改之后如下:

    ClassPathResource classPathResource = new ClassPathResource("ckfinder-config.xml");
                String path1 = classPathResource.getPath();
                InputStream inputStream = classPathResource.getInputStream();
                System.err.println("path1:"+path1);
                System.err.println("inputStream:"+inputStream+",Size:"+inputStream.available());

    证明可以运行没有问题

    详细说明:https://blog.csdn.net/u013467442/article/details/88807557

    复制请注明出处,在世界中挣扎的灰太狼
  • 相关阅读:
    Codeforces 912E
    Codeforces 912D
    洛谷P4980 【模板】Polya定理
    51nod1222最小公倍数计数
    15 Puzzle LightOJ
    loj2734「JOISC 2016 Day 2」女装大佬 || 洛谷P3615 如厕计划
    Jongmah Codeforces
    洛谷P4238【模板】多项式求逆
    洛谷P4721 【模板】分治 FFT
    FFT,NTT
  • 原文地址:https://www.cnblogs.com/XingXiaoMeng/p/12366316.html
Copyright © 2011-2022 走看看