如何在Actuator中启用所有端点(Spring Boot 2.0.0 RC1)

63

我从1.5.10迁移到了Spring Boot 2.0.0 RC1,但在最新版本中的执行器(actuator)上遇到了困难。如何启用公开和启用所有执行器端点?

唯一公开的端点是:

{
  "_links": {
    "self": {
      "href": "http://127.0.0.1:8080/actuator",
      "templated": false
    },
    "health": {
      "href": "http://127.0.0.1:8080/actuator/health",
      "templated": false
    },
    "info": {
      "href": "http://127.0.0.1:8080/actuator/info",
      "templated": false
    }
  }
}

这是我的application.properties文件。有任何想法吗?

#The three first ones seem to be obsolete
endpoints.configprops.enabled=true
endpoints.beans.enabled=true
endpoints.shutdown.enabled=true

management.endpoints.enabled-by-default=true
management.endpoints.sensitive=false
management.endpoints.enabled=true

management.endpoint.configprops.enabled=true
management.endpoint.beans.enabled=true
management.endpoint.shutdown.enabled=true

management.endpoints.web.exposure.include=*

1
请参见 https://dev59.com/_FYM5IYBdhLWcg3wrRqC#48670785,了解非常详细的回答。 - senseiwu
正如@senseiwu发布的链接中所提到的,以endpoints.xyz开头的旧属性已被弃用,应使用以management.xyz开头的属性。因此,在使用任何最新版本的SpringBoot时,您应该依赖于management.endpoints属性并删除根endpoints配置。 - RenatoIvancic
2个回答

145
使用Spring Boot 2.0.0.RC1版本,执行器端点必须满足以下两个条件:1)启用和2)公开。
默认情况下,除了“shutdown”之外的所有端点都是启用的,只有“health”和“info”是公开的。
在您的情况下,以下设置应该有效:
management.endpoints.web.expose=*
# if you'd like to expose shutdown:
# management.endpoint.shutdown.enabled=true

请注意,从Spring Boot 2.0.0.RC2开始,这一点又发生了变化!
management.endpoints.web.exposure.include=*
# if you'd like to expose shutdown:
# management.endpoint.shutdown.enabled=true

有疑问的话,专门的迁移指南始终与最新的变化保持同步。 编辑 为了方便复制粘贴,以下是`yaml´版本 - 截至Spring Boot 2.0.0.RC2
management:
  endpoints:
    web:
      exposure:
        include: "*"

Spring Boot 2.0.0.RC1:
management:
  endpoints:
    web:
      expose: "*"

我已经测试了RC1的解决方案,它完美地运行。点赞。非常感谢。 - Witold Kaczurba
25
application.yml中,我需要输入include: "*"。该句话的意思是包含所有内容。我会尽力保持原文意思的基础上让翻译更通俗易懂。 - A.W.
对我而言,单引号的作用类似于include:'*'。 - naeemgik

2
我需要补充的是,对于Spring Boot 2,执行器的安全性已经发生了变化(在1.X中,执行器的安全性具有单独的配置,这通常会在与用户配置混合时引起问题)。对于Spring Boot 2.X,执行器将不会有单独的安全性配置。根据Spring文档:
“出于安全考虑,默认情况下禁用除/health和/info之外的所有执行器。可以使用management.endpoints.web.expose标志来启用执行器。如果类路径上存在Spring Security并且没有其他WebSecurityConfigurerAdapter,则执行器由Spring Boot自动配置进行安全保护。如果定义了自定义WebSecurityConfigurerAdapter,则Spring Boot自动配置将退出,您将完全控制执行器访问规则。”

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接