首页 > 解决方案 > 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”,但我的应用程序是战争。那是问题吗?

标签: javaspringamazon-web-servicestomcat

解决方案


推荐阅读