java - java.io.FileNotFoundException:类路径资源 [certs/dev/test.crt] 无法解析
问题描述
我的 springboot war 应用程序通过 Elastic beanstalk 部署到 ec2 实例。我正在尝试从资源文件夹中读取文件并获得以下异常。certs 文件夹位于资源文件夹内。
Apr 8 22:42:03 web: java.io.FileNotFoundException: class path resource [certs/dev/test.crt] 无法解析为绝对文件路径,因为它不驻留在文件系统中:jar:file:/var /app/current/target/test-app-0.0.1-SNAPSHOT.war!/WEB-INF/classes!/certs/dev/test.crt
import com.amazonaws.services.iot.client.sample.sampleUtil.SampleUtil;
private ResourceLoader resourceLoader;
Resource certRes = resourceLoader.getResource("classpath:certs/dev/test.crt");
Resource privateRes = resourceLoader.getResource("classpath:certs/dev/private.key");
String certificateFile = certRes.getFile().getPath();
String privateKeyFile = privateRes.getFile().getPath();
SampleUtil.KeyStorePasswordPair pair = SampleUtil.getKeyStorePasswordPair(certificateFile, privateKeyFile);
我尝试使用 ClassLoader.getSystemClassLoader().getResourceAsStream 来读取文件,但 SampleUtil.KeyStorePasswordPair 需要一个路径。
有人可以帮忙吗?
在错误中,我看到“jar:file”,但我的应用程序是战争。那是问题吗?
安
解决方案
推荐阅读
- ruby-on-rails - Rails time_select 避免预填充和存储在 ddbb
- javascript - 如何使用 reduce 来计算总数并修改我的数组?
- r - 使用 stat_function 或 geom_function 时参考子集数据框
- javafx - JavaFX 与 RedHat Open JDK8
- python - 如何扁平化多索引?
- react-native - React-Native gl-model-view 自定义对象导入
- r - 我可以从“map_data”访问“setup_data”的结果吗?(适用于“compute_layout”,但不适用于 ggplot2 ggproto 中的“map_data”)
- git - 知道为什么我会收到此 git 错误:1622754048270
- c++ - 在 SFML 中检测窗口边界冲突的问题
- javascript - 反应不更新窗口间隔中的状态变量