我们有三个Spring Boot应用程序:
我已经设置了服务,以便我们使用Eureka First Discovery,即简单的Web应用程序从eureka服务中找到有关配置服务器的信息.
当单独启动时(在本地或通过将它们作为单独的docker镜像启动)一切正常,即在发现服务运行后启动配置服务器,并在配置服务器运行后启动Simple Web服务.
当docker-compose用于启动服务时,它们显然是在同一时间启动,并且基本上可以竞争启动和运行.这不是问题,因为我们已经添加了failFast:true并重试了简单Web服务的值,并且还重新启动了docker容器,以便在发现服务和配置服务器都是这两个时,最终将重新启动简单的Web服务跑步,但这不觉得最佳.
我们注意到的意外行为如下:
三个问题/意见:
我已经创建了一个示例github repo来演示这种行为:
https://github.com/KramKroc/eurekafirstdiscovery/tree/master
是否有可能为非Spring Boot应用程序提供@ConfigurationProperties行为?为了更清楚地解释一下,我有一个库模块,以后我想在非弹簧启动环境中使用,所以我想知道是否可以使用ConfigurationProperties而不会引入大量的spring-boot核心依赖项.
我发现如果我在 docker-compose 服务条目中覆盖图像的 ENTRYPOINT,它会忽略环境部分中定义的变量,但会从 env 文件中读取它们,例如
someserver:
image: "some-server:latest"
restart: always
ports:
- "8849:8849"
environment:
javaMemoryLimit: 3056M
JAVA_OPTS: "-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=8849 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.rmi.port=8849 -Djava.rmi.server.hostname=localhost"
entrypoint: java ${JAVA_OPTS} -Xmx${javaMemoryLimit} -jar /app.jar
Run Code Online (Sandbox Code Playgroud)
当我这样做时docker-compose up,我收到有关未设置变量的警告:
WARNING: The JAVA_OPTS variable is not set. Defaulting to a blank string.
WARNING: The javaMemoryLimit variable is not set. Defaulting to a blank string.
Run Code Online (Sandbox Code Playgroud)
但是当我在 env 文件中定义变量时,例如 .env
javaMemoryLimit=2098M
JAVA_OPTS=-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=8849 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.rmi.port=8849 -Djava.rmi.server.hostname=localhost
Run Code Online (Sandbox Code Playgroud)
然后变量按预期扩展。