如何让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
相关产品推荐
相关产品推荐

