【问题标题】:How to setup stage-specific microprofile config with java-ee8, microProfile 4.0, Openliberty 21 and Docker如何使用 java-ee8、microProfile 4.0、Openliberty 21 和 Docker 设置特定于阶段的微配置文件配置
【发布时间】:2021-09-02 04:46:48
【问题描述】:

我的应用程序在 docker 容器内使用 JavaEE8、Openliberty 21.0.0.5 和 Microprofile 4.0 时遇到问题。 我无法从图像“外部”设置 mpConfig-2.0-introduced mp.config.profile。 我的设置如下:

microprofile-config.properties
microprofile-config-dev.properties
microprofile-config-prod.properties

src/main/resources/META-INF/

功能在 server.xml 中正确激活,并在启动时正确安装。

<featureManager onError="WARN">
    <feature>microProfile-4.0</feature>
    <feature>javaee-8.0</feature>
</featureManager>

每个阶段我还有一个 server.env,它通过 docker run 的 --env-file 传递给我的容器。

我的第一种方法是在server.env 中设置mp.config.profile,因为它可以 在不同阶段运行图像时发生更改。 f.e. mp.config.profile=devserver-dev.env 等等。 但是 microprofile-config-dev.properties 的值从不用于此设置。

我能够正确激活配置文件的唯一方法是在使用时

<variable name="mp.config.profile" value="dev" />

server.xml内。

但是,server.xml 在 docker 映像中不是特定于阶段的,因此无法在不同阶段更改它。

有没有人建议这样做的正确方法是什么?

提前致谢

问候

【问题讨论】:

    标签: java docker open-liberty microprofile eclipse-microprofile-config


    【解决方案1】:

    如果您想从server.env 设置mp.config.profile,您可能需要改为设置MP_CONFIG_PROFILE

    由于点在环境变量名称中无效,MP Config defines some mapping rules 从环境变量中查找配置时。它将检查请求的名称,其中非字母数字字符转换为下划线,然后再次将所有字母转换为大写。

    【讨论】:

    • 我很确定我已经尝试过带下划线的小写和大写,但显然我在尝试时遇到了其他一些错误配置。无论如何,它现在有效。谢谢!
    猜你喜欢
    • 2019-02-12
    • 2019-12-08
    • 2011-12-19
    • 2016-12-26
    • 2023-01-30
    • 2012-09-17
    • 2011-10-28
    • 2021-06-10
    • 2020-02-25
    相关资源
    最近更新 更多