You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让Liberty的MicroProfile Health 4.0识别Spring Boot 3的@Readiness Bean

解决Liberty中MPHealth无法识别Spring上下文Bean的问题
  • 启用Liberty的Spring Boot集成特性
    你当前未在server.xml的<featureManager>中启用Spring相关特性,而Liberty的MPHealth默认仅扫描CDI Bean,无法感知Spring上下文内的Bean。需添加springBoot-3.0特性,让Liberty自动桥接Spring上下文与CDI容器:

    <featureManager>
        <feature>mpHealth-4.0</feature>
        <feature>springBoot-3.0</feature>
    </featureManager>
    
  • 可选补充:确保Bean同时被Spring和CDI管理
    若启用上述特性后仍无效果,可给健康检查Bean额外添加@javax.inject.Named注解,让它同时被Spring和CDI容器识别:

    @Readiness
    @Component
    @Named
    class ConnectionReadyHealthCheck(val apiClient: APIClient) : HealthCheck {
        companion object {
            val NAME = "apiConnection"
        }
        override fun call(): HealthCheckResponse {
            return if(apiClient.isConnected()) {
                HealthCheckResponse.up(NAME)
            } else {
                HealthCheckResponse.down(NAME)
            }
        }
    }
    
  • 验证配置
    重启Liberty服务器后,访问 readiness 健康检查端点(默认路径为/health/ready),确认返回结果中包含apiConnection的健康状态。

内容的提问来源于stack exchange,提问作者mikeb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 09:06:08