spring boot 打包jar后访问classes文件夹的文件提示地址不存在

报错内容:class path resource [client.p12] cannot be resolved to absolute file path because it does not reside in the file system

问题所在:

             代码使用了 ResourceUtils.getFile("classpath:client.p12")访问文件 ,这个方法只能从类路径下获取文件,无法从jar包中获取,所以打成jar包后发布到windows系统,就报错找不到文件了.

解决方案

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

注:使用类加载器不会对classpath做处理,因此使用类加载器读取文件,路径中不要添加classpath 

原文地址:https://www.cnblogs.com/XM-CHC/p/11170445.html