gpt4 book ai didi

java - Springboot - AWS Elasticbeanstalk - 资源无法解析

转载 作者:行者123 更新时间:2023-12-02 09:26:05 24 4
gpt4 key购买 nike

有谁知道当应用程序在AWS Elasticbeanstalk上运行时如何从资源文件夹中读取文件?

请参阅下面的代码:

Resource resource = new ClassPathResource("application.properties");
File file = resource.getFile();
Map propsMap = PropertyUtil.readProperties(file);

enter image description here

这是错误消息:

java.io.FileNotFoundException:类路径资源 [application.properties] 无法解析为绝对文件路径,因为它不驻留在文件系统中:jar:file:/var/app/current/application.jar!/BOOT-INF/classes!/application.properties"

提前谢谢您。

最佳答案

您可能应该只更改 PropertyUtil 以便能够从 InputStream 中读取:

Properties properties = new Properties();
try (InputStream stream =
new ClassPathResource("application.properties").getInputStream()) {
properties.load(stream);
}

Properties 类已经是 Map 实现,因此您无需更改任何其他代码。

关于java - Springboot - AWS Elasticbeanstalk - 资源无法解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58334203/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com