Spring Boot Actuator/运行状况端点不显示数据库或文件系统信息



我无法获取数据库信息或文件系统信息以显示在/health端点上。我只能得到:

{
  "status": "UP"
}

有关我的设置和配置的详细信息:-弹簧套1.3.3-在JBoss EAP 6.4上运行WAR-数据源是JNDI资源。-Oracle是数据库

spring:
  datasource:
    # Must match the datasource name in JBoss standalone.xml
    jndi-name: java:jboss/beautiful-ds
    driver-class-name: oracle.jdbc.driver.OracleDriver
  jpa:
    properties:
      # escapes reserved words used as column names (if any)
      globally_quoted_identifiers: true
    show-sql: true
    hibernate:
        naming_strategy: org.hibernate.cfg.EJB3NamingStrategy
server:
  servlet-path: /*
management:
  health:
    diskspace:
      enabled: true
    db:
      enabled: true
endpoints.health.sensitive: false

我在/configprops上发现了一件事,我不确定它是否相关:

  "spring.datasource.CONFIGURATION_PROPERTIES": {
    "prefix": "spring.datasource",
    "properties": {
      "error": "Cannot serialize 'spring.datasource'"
    }

我曾尝试添加"驱动程序类名:oracle.jdbc.driver.OracleDriver",认为它可能需要更多细节,但这并没有改变这种情况。

那么,是的,是什么?我做了一个普通的示例项目,它至少显示了文件系统的内容,所以不确定为什么两者都不想在我的"真实"应用程序中显示。告诉我你伟大而明智的答案!:)

默认情况下,Spring将以下属性设置为never。若要查看完整的运行状况详细信息,请将以下属性添加到application.properties

management.endpoint.health.show-details=always

来自spring-boot文档:

45.6 HealthIndicators 的安全性

HealthIndicators返回的信息本质上往往有些敏感。例如您可能不想将数据库服务器的详细信息发布到世界。因此,默认情况下,只有运行状况为通过未经身份验证的HTTP连接公开。如果你为您可以设置的始终公开的完整健康信息endpoints.health.对错误敏感。运行状况响应也被缓存以防止"拒绝服务"攻击。使用endpoints.health.time-to-live属性(如果要更改默认缓存周期为1000毫秒。

请确保设置了以下属性。

endpoints.health.sensitive=true # Mark if the endpoint exposes sensitive information.
management.health.db.enabled=true # Enable database health check.
management.health.defaults.enabled=true # Enable default health indicators.
management.health.diskspace.enabled=true # Enable disk space health check.

如果您使用的是spring安全性,那么默认情况下会为执行器端点启用安全性,请在yml文件-中禁用它

management:
    security:
           enabled: false

IIUC,聚合运行状况显示在/health下,至少对于springboot2为(IIUC)。这意味着,即使你把所有的东西都配置得恰到好处,也只会显示一行。

更新:如果这不是你所需要的,你必须特别要求查看详细信息。检查这些设置:

management.endpoint.health.show-details=when-authorized
management.endpoint.health.roles=ADMIN

您在配置文件中混合了YAML和Properties语法。用以下内容替换最后一行,它应该可以工作:

endpoints:
    health:
        sensitive: false

最新更新