如何启用执行器中的所有端点(Spring Boot 2.0.0 RC1)

问题描述 投票:0回答:2

我从 1.5.10 迁移到 Spring Boot 2.0.0 RC1,并且我坚持使用最新版本的执行器。如何启用公开并启用所有执行器端点?

唯一暴露的端点是:

{
  "_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=*
java spring spring-boot spring-boot-actuator
2个回答
140
投票

使用 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.RC 开始,这一点发生了变化(再次!)2

management.endpoints.web.exposure.include=*
# if you'd like to expose shutdown:
# management.endpoint.shutdown.enabled=true

毫无疑问,专用迁移指南始终与最新更改保持同步。

编辑

为了方便复制和粘贴,这里是“yaml”版本 - 从 Spring Boot 2.0.0.RC 开始2

management:
  endpoints:
    web:
      exposure:
        include: "*"

Spring Boot 2.0.0.RC1

management:
  endpoints:
    web:
      expose: "*"

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 自动配置将退出,您将完全控制执行器访问规则。)

© www.soinside.com 2019 - 2024. All rights reserved.