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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48900892/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 02:55:43  来源:igfitidea点击:

How to enable all endpoints in actuator (Spring Boot 2.0.0 RC1)

javaspringspring-bootspring-boot-actuator

提问by Witold Kaczurba

I moved to Spring Boot 2.0.0 RC1 from 1.5.10 and I am stuck with actuator in the latest version. How can I enable expose and enable all actuator endpoints?

我从 1.5.10 迁移到 Spring Boot 2.0.0 RC1,但我一直在使用最新版本的执行器。如何启用公开和启用所有执行器端点?

The only endpoints that get exposed are:

唯一暴露的端点是:

{
  "_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
    }
  }
}

This is my application.propertiesfiles. Any ideas?

这是我的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=*

采纳答案by Brian Clozel

With Spring Boot 2.0.0.RC1, actuator endpoints must be 1) enabled and 2) exposed.

使用 Spring Boot 2.0.0.RC1,执行器端点必须 1) 启用和 2) 公开。

By default, all endpoints but shutdownare enabled and only healthand infoare exposed.

默认情况下,所有端点但shutdown被启用,只有healthinfo暴露。

In your case, the following should work:

在您的情况下,以下应该有效:

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

Note that this changes (again!) as of Spring Boot 2.0.0.RC2:

请注意,从 Spring Boot 2.0.0.RC2 开始,这(再次!)发生了变化:

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

In doubt, the dedicated migration guideis always up-to-date with the latest changes.

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

Edit

编辑

For easy copy and paste, here's the `yaml′ versions - as of Spring Boot 2.0.0.RC2:

为了便于复制和粘贴,这里是 `yaml' 版本 - 从 Spring Boot 2.0.0.RC2 开始:

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

before:

前:

management:
  endpoints:
    web:
      expose: "*"

回答by Przemek Nowak

I will add that for Spring Boot 2 the actuator security has been changed (for 1.X the security for actuator has separate configuration what often cause problems when it mixes with user configuration). For Spring Boot 2.X the actuator won't have separate security config. According to Spring documentation:

我将补充一点,对于 Spring Boot 2,执行器安全性已更改(对于 1.X,执行器的安全性具有单独的配置,当它与用户配置混合时通常会导致问题)。对于 Spring Boot 2.X,执行器不会有单独的安全配置。根据 Spring 文档:

For security purposes, all actuators other than /health and /info are disabled by default. The management.endpoints.web.expose flag can be used to enable the actuators. If Spring Security is on the classpath and no other WebSecurityConfigurerAdapter is present, the actuators are secured by Spring Boot auto-config. If you define a custom WebSecurityConfigurerAdapter, Spring Boot auto-config will back off and you will be in full control of actuator access rules.)

出于安全目的,默认情况下禁用除 /health 和 /info 之外的所有执行器。management.endpoints.web.expose 标志可用于启用执行器。如果 Spring Security 在类路径上并且不存在其他 WebSecurityConfigurerAdapter,则执行器由 Spring Boot 自动配置保护。如果你定义了一个自定义的 WebSecurityConfigurerAdapter,Spring Boot 的自动配置将会关闭,你将完全控制执行器访问规则。)