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

Spring Boot与Grails项目中Actuator健康端点返回结果差异问题咨询

Grails框架默认对Spring Boot Actuator的健康检查规则做了裁剪,默认不会展示全部组件的健康详情、也不会自动注册所有依赖对应的健康指示器,按以下步骤调整即可和原生Spring Boot返回结构一致:

第一步:调整Actuator核心配置

在grails-app/conf/application.yml中添加如下配置:

management:
  endpoint:
    health:
      # 总是展示健康详情,对应原生Spring Boot的全量详情输出
      show-details: always
      # 开启components层级结构展示,和Spring Boot返回结构对齐
      show-components: always
  endpoints:
    web:
      exposure:
        # 确保health端点暴露,如需暴露所有端点可写为 "*"
        include: health
  # 开启所有默认健康指示器的自动装配
  health:
    defaults:
      enabled: true

如果使用的是application.properties配置文件,对应配置如下:

management.endpoint.health.show-details=always
management.endpoint.health.show-components=always
management.endpoints.web.exposure.include=health
management.health.defaults.enabled=true

注意:如果是Grails 3.x(对应Spring Boot 1.x版本),不需要配置show-components参数,该参数是Spring Boot 2.x新增,1.x版本默认就会展示components层级内容

第二步:补全缺失的健康指示器(可选)

如果调整配置后还是缺少数据库、RabbitMQ、邮件等特定组件的健康信息,是因为Grails默认没有自动注册部分Spring Boot的健康指示器,可在grails-app/conf/spring/resources.groovy中手动注册需要的健康指示器Bean:

import org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator
import org.springframework.boot.actuate.amqp.RabbitHealthIndicator
import org.springframework.boot.actuate.mail.MailHealthIndicator

beans = {
    // 数据库健康检查,引用Grails自动注册的dataSource Bean
    dbHealthIndicator(DataSourceHealthIndicator, ref('dataSource'))
    // RabbitMQ健康检查,引用项目中已配置的rabbitTemplate Bean
    rabbitHealthIndicator(RabbitHealthIndicator, ref('rabbitTemplate'))
    // 邮件服务健康检查,引用项目中已配置的javaMailSender Bean
    mailHealthIndicator(MailHealthIndicator, ref('javaMailSender'))
}

第三步:检查依赖版本适配

确保spring-boot-starter-actuator的版本和当前Grails版本依赖的Spring Boot版本完全一致,避免跨版本导致的功能异常:

  • Grails 4.x对应Spring Boot 2.1.x版本
  • Grails 3.3.x对应Spring Boot 1.5.x版本
    可通过在build.gradle中指定版本号确保适配:
dependencies {                
    compile "org.springframework.boot:spring-boot-starter-actuator:2.1.18.RELEASE" // Grails4对应版本示例
}

调整完成后重启项目,访问/actuator/health即可得到和原生Spring Boot完全一致的返回内容。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.07 16:39:00