java - Spring Boot Jar 需要从类路径中读取 Keystore 作为文件
问题描述
在src/main/resources
我有一个文件夹files
。目标是读取文件并在下面的代码中使用它们
@PostConstruct
public void init() {
....
File jks = null;
try {
final FileInputStream fin = new FileInputStream(ResourceUtils.getFile("classpath*:files/prod-apicrypt.cer"));
jks = ResourceUtils.getFile("classpath*:files/mykeystore.jks");
.....
}catch(Exception e){
//handling
}
...
这在 IDE 中有效,但当mvn spring-boot:run
我创建 jar 并尝试运行它时,我FileNotFoundException
从 .cer 文件中获取。我想密钥库也会发生同样的情况。
问题是我不能像在其他回复中发现的那样,只做一个 Inputstream 并逐行读取文件。
我认为我必须缺少一些基本的东西,因为 Spring Boot 肯定有一种从类路径读取文件的方法。我只是不知道是什么。
解决方案
推荐阅读
- docker - 使用 AWS 日志记录驱动程序配置运行 docker 容器时,Systemd Unit 引发错误
- javascript - 如何使用 jquery 仅在解析的 xml 上选择父节点
- tfs - VSTS 代码部分不显示
- java - 后备意图不为 Web 集成提供履行文本
- android - Facebook:从用户 ID 获取公开照片
- java - 在android中的下午4:00将时间戳字符串转换为DayName-Month-year?
- android - Android:仅由用户检测搜索栏更改
- docker - Kafka streams.allMetadata() 在 DOCKER 中返回空列表(交互式查询)
- javascript - 测试计算器的小数字符串
- ruby-on-rails - 我的模型中的实体/对象的路径与 route.rb 不同?