工作中需要把一个证书文件打包到jar包中供读取使用,目录结构如下:
在本地(未打包)测试的时候读取没有问题,但在测试环境(打包后)报如下错误:
1 | java.io.FileNotFoundException: class path resource [wep/test.p12] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/D:/LL/wepay.jar!/BOOT-INF/classes!/wep/test.p12 |
代码如下:
1 | final String resourceLocation = "classpath:wep/"+wepayConfig.getCertFile(); |
换成下面的代码可以解决这个问题
1 | ClassPathResource resource = new ClassPathResource("wep/"+wepayConfig.getCertFile()); |