包括 mpHealth 功能会破坏 Open Liberty 中的独立应用程序

Including mpHealth feature breaks standalone application in Open Liberty

我目前正在使用 Open Liberty 18.0.0.4 及其 Microprofile 支持。当我尝试构建一个包含 mpHealth-1.0 功能的独立可运行 Jar 时,启动失败

[ERROR   ] CWWKF0033E: The singleton features com.ibm.websphere.appserver.javax.servlet-3.1 and com.ibm.websphere.appserver.javax.servlet-4.0 cannot be loaded at the same time.  The configured features mpHealth-1.0 and jaxrs-2.1 include one or more features that cause the conflict. Your configuration is not supported; update server.xml to remove incompatible features.
[ERROR   ] CWWKF0033E: The singleton features com.ibm.websphere.appserver.javax.annotation-1.2 and com.ibm.websphere.appserver.javax.annotation-1.3 cannot be loaded at the same time.  The configured features mpHealth-1.0 and jaxrs-2.1 include one or more features that cause the conflict. Your configuration is not supported; update server.xml to remove incompatible features.
[ERROR   ] CWWKF0033E: The singleton features com.ibm.websphere.appserver.javaeeCompatible-8.0 and com.ibm.websphere.appserver.javaeeCompatible-7.0 cannot be loaded at the same time.  The configured features jsonb-1.0 and mpHealth-1.0 include one or more features that cause the conflict. Your configuration is not supported; update server.xml to remove incompatible features.
[ERROR   ] CWWKF0033E: The singleton features com.ibm.websphere.appserver.javax.cdi-2.0 and com.ibm.websphere.appserver.javax.cdi-1.2 cannot be loaded at the same time.  The configured features jsonb-1.0 and mpHealth-1.0 include one or more features that cause the conflict. Your configuration is not supported; update server.xml to remove incompatible features.

我使用的是 jaxrs-2.1 和 jsonb-1.0,一切正常。一旦添加 mpHealth-1.0 功能,我就会收到上述错误。这是 server.xml 的相关片段:

    <featureManager>
        <feature>jaxrs-2.1</feature>
        <feature>jsonb-1.0</feature>
        <feature>mpHealth-1.0</feature>
    </featureManager>

这就是开始的 Jar 在结束时所说的(但没有服务可用):

[AUDIT   ] CWWKF0012I: The server installed the following features: [jsonb-1.0, servlet-4.0, jndi-1.0, mpHealth-1.0, json-1.0, cdi-1.2, jsonp-1.1, jaxrsClient-2.1, jaxrs-2.1].

发生此错误是因为并非所有 OpenLiberty 功能都相互兼容,如果您启用冲突的功能,您会收到一条错误消息,指示哪些功能发生冲突。它应该可以通过在 server.xml 中启用其他功能来解决,以帮助运行时消除应启用哪些功能的歧义。

功能冲突的两个主要原因是:

  1. 尝试启用同一功能的两个版本(例如 foo-1.0foo-2.0
  2. 启用了 Java EE 7 和 Java EE 8 功能的混合(例如,来自 EE 7 的 cdi-1.2 和来自 EE 8 的 jaxrs-2.1

要分解您启用的功能依赖性,它看起来像这样:

- jsonb-1.0 -> jsonp-1.1
- jaxrs-2.1 -> cdi-2.0
            -> servlet-4.0
- mpHealth-1.0 -> cdi-1.2 (tolerates cdi-2.0)

您看到这些错误的原因是因为 OpenLiberty 功能管理器没有足够的证据知道它可以故障转移到 mpHealth-1.0 -> cdi-2.0 依赖项。

要解决此问题,您有两种选择:

  1. 在 server.xml 中启用 cdi-2.0 功能。这应该有助于消除功能管理器的歧义,以便它可以故障转移到 mpHealth-1.0 -> cdi-2.0 依赖项。
  2. 不启用个别功能,而是启用 microProfile-2.0 便利功能。在这里您不必担心功能冲突,但它会将更多功能加载到运行时(例如 MP Metrics、MP Config、MP Fault Tolerance 等),这将产生一些额外的启动时间和内存占用成本。