【发布时间】:2021-05-28 09:38:46
【问题描述】:
我正在尝试读取位于 src/main/resources 下的 json 文件,这在本地工作得很好,但是在构建 docker-image 后,相同的代码在部署时报告“IOException - File not found”。
这是试图加载到类中的代码:
@Component
public class KontorAdmin {
List<KontorInfo> kontorer;
String filePath = "./src/main/resources/kontortoggle.json";
public KontorAdmin() throws IOException {
initKontor();
}
public void initKontor() throws IOException {
File file = new File(filePath);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
KontorWrapper kontorWrapper = objectMapper.readValue(file, KontorWrapper.class);
this.kontorer = kontorWrapper.getKontorer();
}
这里是 dockerfile:
FROM openjdk:11
VOLUME /tmp
ADD target/rek-service.jar rek-service.jar
EXPOSE 80:80
ENTRYPOINT ["java","-jar","rek-service.jar"]
我想我可以将文件添加到 docker,但是我如何让它在本地通过单元测试,这需要不同的文件路径?
感谢您的帮助
【问题讨论】:
标签: java spring-boot docker filenotfoundexception