简体   繁体   English

如何使用 java-ee8、microProfile 4.0、Openliberty 21 和 Docker 设置特定于阶段的 microprofile 配置

[英]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.

相关问题 Java EE微格式 - Java EE Microprofile 微型轮廓| 配置-使用动态值进行测试 - Microprofile | Config - Testing with dynamic values 为官方 Docker 映像 microProfile3java11 打开 Liberty SSLHandshakeException - Open Liberty SSLHandshakeException for official Docker image microProfile3java11 带有eclipse microprofile-config的自定义配置文件 - Custom config file with eclipse microprofile-config 如何在 Java Microprofile 中正确编写异步 POST/GET - How to write async POST/GET in Java Microprofile correctly Thorntail中MicroProfile Config实现的可移植性问题 - Portability issue with MicroProfile Config implementation in Thorntail 在自定义 OASFilter 处理期间,Microprofile 配置注入是 null,并且 microprofile-config.propetries 不被视为配置源 - Microprofile Config injection is null during custom OASFilter processing and microprofile-config.propetries is not considered as config source 如何模拟配置提供程序类 (org.eclipse.microprofile.config.ConfigProvider) - How to Mock Config Provider Class ( org.eclipse.microprofile.config.ConfigProvider) Java Quarkus/MicroProfile Restclient注入sslContext - Java Quarkus/MicroProfile Restclient inject sslContext 如何使用 OAuth 对 MicroProfile REST 客户端调用进行身份验证? - How to authenticate MicroProfile REST Client calls with OAuth?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM