Springboot-AWS Elasticbeanstalk-无法解析资源

问题描述 投票:0回答:1

当应用程序在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“

谢谢你。

java amazon-web-services spring-boot amazon-elastic-beanstalk filenotfoundexception
1个回答
1
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.