Springboot-AWS Elasticbeanstalk-资源无法解析

时间:2019-10-11 04:19:38

标签: java amazon-web-services spring-boot amazon-elastic-beanstalk filenotfoundexception

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

谢谢。

1 个答案:

答案 0 :(得分:1)

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

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

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