优米格
分享有营养的

Spring Boot读取jar包文件错误解决

BraUndress.png

从jar包中读取classpath下文件出错:

java.io.FileNotFoundException: class path resource [conf/sendofd.xml] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/home/wuhui/component/da
ta/data-query-3.0.1.jar!/BOOT-INF/classes!/conf/sendofd.xml

解决办法:

Resource resource = new ClassPathResource("/" + relativePath);
        InputStream fileInputStream = null;
        try {
            fileInputStream = resource.getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }

更多方法参考: Spring Boot如何从classpath下读取文件(jar打包/war打包)

赞(0)
未经允许禁止转载:优米格 » Spring Boot读取jar包文件错误解决

评论 抢沙发

合作&反馈&投稿

商务合作、问题反馈、投稿,欢迎联系

广告合作侵权联系