[英]How to setup stage-specific microprofile config with java-ee8, microProfile 4.0, Openliberty 21 and Docker
I have a problem with my application using JavaEE8, Openliberty 21.0.0.5 and Microprofile 4.0 inside a docker container.我的应用程序在 docker 容器中使用 JavaEE8、Openliberty 21.0.0.5 和 Microprofile 4.0 时遇到问题。 I cannot set the mpConfig-2.0-introduced
mp.config.profile
from "outside" the image.我无法从图像的“外部”设置 mpConfig-2.0 引入的
mp.config.profile
。 My setup is as follows:我的设置如下:
microprofile-config.properties
microprofile-config-dev.properties
microprofile-config-prod.properties
inside src/main/resources/META-INF/
在
src/main/resources/META-INF/
Features are correctly activated inside server.xml and are installed correctly on startup.功能在 server.xml 中正确激活并在启动时正确安装。
<featureManager onError="WARN">
<feature>microProfile-4.0</feature>
<feature>javaee-8.0</feature>
</featureManager>
I also have one server.env per stage that is passed to my container via docker run's --env-file
.每个阶段我还有一个 server.env ,它通过
--env-file
run 的--env-file
传递给我的容器。
My first approach was to set mp.config.profile
inside the server.env
since it can be changed when running the image on different stages.我的第一种方法是在
server.env
设置mp.config.profile
因为它可以在不同阶段运行图像时更改。 fe mp.config.profile=dev
inside server-dev.env
an so forth. fe
mp.config.profile=dev
里面的server-dev.env
等等。 However the values of microprofile-config-dev.properties are never used with this setup.但是 microprofile-config-dev.properties 的值从未与此设置一起使用。
The only way I was able to correctly activate the config profile was when using我能够正确激活配置文件的唯一方法是使用
<variable name="mp.config.profile" value="dev" />
inside the server.xml
.在
server.xml
里面。
However the server.xml
is not stage-specific inside the docker image, so it won't be possible to change it on different stages.但是
server.xml
在 docker 镜像中不是特定于阶段的,因此不可能在不同的阶段更改它。
Does anyone have a suggestions what is the correct way to do this?有没有人建议这样做的正确方法是什么?
Thanks in advance提前致谢
Regards问候
If you want to set mp.config.profile
from server.env
, you probably need to set MP_CONFIG_PROFILE
instead.如果你想从
server.env
设置mp.config.profile
,你可能需要设置MP_CONFIG_PROFILE
。
Since dots aren't valid in environment variable names, MP Config defines some mapping rules when looking up config from environment variables.由于点在环境变量名称中无效,因此 MP Config 在从环境变量中查找配置时定义了一些映射规则。 It will check for the requested name with non-alphanumeric characters converted to underscores, and then again also with all letters converted to uppercase.
它将检查请求的名称,将非字母数字字符转换为下划线,然后再次将所有字母转换为大写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.