spring-boot - Dockerized spring-boot web 服务抛出 FileNotFound 异常
问题描述
我尝试使用 Docker File 命令将文件从我的 Windows 机器复制到 Docker 容器,并从 spring web service 读取这些文件。Webservice 抛出错误文件未找到!
在这里,我试图将我的本地目录 src/nlp 复制到 /data 容器目录
以下是可用的 docker 卷
码头工人文件
FROM openjdk:8-jdk-alpine
EXPOSE 8080
ARG JAR_FILE=/target/nlp-0.0.1-SNAPSHOT.jar
ADD ${JAR_FILE} nlp-0.0.1-SNAPSHOT.jar
ADD src/nlp /data
ENTRYPOINT ["java","-jar", "nlp-0.0.1-SNAPSHOT.jar"]`
应用程序属性
server.port=8080
logging.level.radial.nlp=DEBUG
logging.file = mylogfile.log
nlp.learning.dir = /data/
爪哇
InputStream inputStream = new FileInputStream(environment.getProperty("nlp.learning.dir")+ "/train/models/en/token/en-token.bin");
错误
java.io.FileNotFoundException: /data/train/models/en/token/en-token.bin (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
解决方案
我已经更改了我的 Maven 插件依赖项,现在它工作正常
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.7</version>
<!-- Wire up to the default build phases -->
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>${project.artifactId}</repository>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
推荐阅读
- node.js - 使用 prismjs 生成静态 html - 如何启用行号?
- laravel - 如果所有数据彼此不相关,如何在单页中调用多表数据
- npm - 未知选项:.presents,Entrypoint undefined = index.html,导入在 index.js 文件中不起作用
- python - 我从 Pyinstaller 转换的 .exe 文件无法运行
- java - 如何通过前端网页从远程机器访问托管服务器文件目录
- typescript - 如何在 ngx-admin 模板中使组件全屏显示?
- javascript - 计算仪表值以绘制仪表 svg 路径的公式
- react-native - 在 react native 天才聊天中,哪些道具用于在工具栏中添加图像和相机等额外功能?我如何实现它?
- haskell - 将自身作为参数的函数的 Hindley-Milner 类型
- javascript - 如何将 Javascript 文件动态加载到 HTML 中