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 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM