oracle Spring Boot Actuator /health 端点不显示数据库或文件系统信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36428349/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring Boot Actuator /health endpoint does not show database or file system information
提问by jeremy simon
I cannot get database information or filesystem information to show up on the /health endpoint. I only can get:
我无法获取数据库信息或文件系统信息以显示在 /health 端点上。我只能得到:
{
"status": "UP"
}
Details about my setup and configuration: - Spring Boot 1.3.3 - Running the WAR on JBoss EAP 6.4 - Datasource is a JNDI resource. - Oracle is the database
关于我的设置和配置的详细信息: - Spring Boot 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
One thing i found on /configprops is this, which I'm not sure whether it is related:
我在 /configprops 上发现的一件事是,我不确定它是否相关:
"spring.datasource.CONFIGURATION_PROPERTIES": {
"prefix": "spring.datasource",
"properties": {
"error": "Cannot serialize 'spring.datasource'"
}
I had tried adding "driver-class-name: oracle.jdbc.driver.OracleDriver" thinking it maybe needed more details, but that didn't change the situation.
我曾尝试添加“驱动程序类名称:oracle.jdbc.driver.OracleDriver”,认为它可能需要更多细节,但这并没有改变情况。
so yeah, what gives? I made a vanilla example project which at least shows the filesystem stuff out the gate, so not sure why either don't want to show in my "real" app. Tell me your great and wise answers! :)
所以是的,什么给了?我做了一个普通的示例项目,它至少显示了文件系统的内容,所以不确定为什么不想在我的“真实”应用程序中显示。告诉我你伟大而明智的答案!:)
回答by saikiran
By default Spring sets the below property to never
.
To be able to see full health details add the below property to your application.properties
.
默认情况下,Spring 将以下属性设置为never
. 为了能够查看完整的健康详细信息,请将以下属性添加到您的application.properties
.
management.endpoint.health.show-details=always
回答by Freelancer
In cases if you are using spring security, then by default security is enabled for actuator endpoints, disable it in your yml file -
如果您使用的是 spring 安全性,那么默认情况下为执行器端点启用了安全性,请在您的 yml 文件中禁用它 -
management:
security:
enabled: false
回答by TheKojuEffect
From the spring-boot
documentation:
从spring-boot
文档:
45.6 Security with HealthIndicators
Information returned by HealthIndicators is often somewhat sensitive in nature. For example, you probably don't want to publish details of your database server to the world. For this reason, by default, only the health status is exposed over an unauthenticated HTTP connection. If you are happy for complete health information to always be exposed you can set endpoints.health.sensitive to false. Health responses are also cached to prevent “denial of service” attacks. Use the endpoints.health.time-to-live property if you want to change the default cache period of 1000 milliseconds.
45.6 HealthIndicators 的安全性
HealthIndicators 返回的信息本质上通常有些敏感。例如,您可能不想向全世界发布您的数据库服务器的详细信息。因此,默认情况下,未经身份验证的 HTTP 连接仅公开健康状态。如果您希望始终公开完整的健康信息,您可以将 endpoints.health.sensitive 设置为 false。健康响应也被缓存以防止“拒绝服务”攻击。如果要更改 1000 毫秒的默认缓存周期,请使用 endpoints.health.time-to-live 属性。
Make sure to have following properties set.
确保设置了以下属性。
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.
回答by Martin Mucha
IIUC, the aggregate health is shown under /health, at least (IIUC) for springboot2. Meaning, that even if you have everything configured just right, only one line will be shown.
IIUC,聚合健康显示在/health下,至少是springboot2的(IIUC)。这意味着,即使您的所有配置都正确,也只会显示一行。
UPDATE: and if this is not what you need, you have to specifically ask to see details. Check these settings:
更新:如果这不是您需要的,您必须特别要求查看详细信息。检查这些设置:
management.endpoint.health.show-details=when-authorized
management.endpoint.health.roles=ADMIN
回答by dunni
You mixed YAML and Properties syntax in your configuration file. Replace the last line by the following, and it should work:
您在配置文件中混合了 YAML 和 Properties 语法。用以下内容替换最后一行,它应该可以工作:
endpoints:
health:
sensitive: false