解决方案
椅子和键盘之间存在错误
问题是 SPRING_PROFILES_ACTIVE 环境变量指向不存在的配置文件。将其更改为正确的名称解决了问题。我本以为 Spring 会输出一个关于此的错误,但是哦,好吧。
原始问题:
我有一个在 Java10 中使用 Spring boot 运行的“hello world”Java 应用程序构建。它直接在我的机器上运行良好,但是当尝试使用 docker 启动它时,它会卡在以下输出中:
(The Srping ascii art)
:: Spring Boot :: (v2.0.1.RELEASE)
WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (jar:file:/app.jar!/BOOT-INF/lib/groovy-2.4.15.jar!/) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
正在运行的进程:
java -Xmx800m -Djava.security.egd=file:/dev/./urandom -jar /app.jar
它直接在我的笔记本电脑(Mac OS)和我同事的笔记本电脑(Windows 7)上运行良好,但在本地和 Kubernetes (AWS) 上的 docker 中都失败了
我尝试将 spring 日志级别配置为 DEBUG,但没有效果。
我还尝试编辑 $JAVA_HOME/conf/security/java.security
来直接更改 java securerandom.source 属性,但这也不起作用。
编辑: dockerfile 是使用以下内容的 FROM:
FROM openjdk:10-jdk
RUN apt-get update && \
apt-get install -y openssl curl
ADD java.security /docker-java-home/conf/security/java.security
ONBUILD ARG BUILD_VERSION_NO="no-version"
ENV SPRING_PROFILES_ACTIVE=prod
#ENV JAVA_OPTS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,suspend=n"
ONBUILD COPY target/*.jar app.jar
ONBUILD RUN sh -c 'touch /app.jar'
ONBUILD RUN echo "$BUILD_VERSION_NO" > /version
EXPOSE 8080
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -jar /app.jar" ]
我的笔记本电脑中的java版本是
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
使用等效的 openjdk 打包应用程序并不能解决问题
openjdk version "10.0.1" 2018-04-17
OpenJDK Runtime Environment (build 10.0.1+10)
OpenJDK 64-Bit Server VM (build 10.0.1+10, mixed mode)
最佳答案
回答我自己的问题,以防其他人遇到这个问题:
SPRING_PROFILES_ACTIVE 环境变量包含“prod”,而应用程序中的 spring 配置文件是“pro”。更改 Dockerfile 中的值解决了该问题。
关于java - Spring Boot 应用程序在使用 Java 10 的 Docker 中启动时卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49977555/