【问题标题】:Is there any way to by default expose custom actuator endpoints有什么方法可以默认公开自定义执行器端点
【发布时间】:2021-04-22 18:26:50
【问题描述】:

今天如果我想公开我的自定义执行器端点,我必须在 application.properties 的配置下面添加

management.endpoints.web.exposure.include=info,health,myAwesomeActuator
@Component
@Endpoint(id = "myAwesomeActuator")
public class MyAwesomeActuator {

    @ReadOperation
    public String test() {
        return "Hello, from MyAwesomeActuator";
    }
}

如果我不添加上面的配置 Spring Boot 默认只公开 /health/info 端点

有什么方法可以将我的执行器标记为默认暴露?

【问题讨论】:

    标签: java spring-boot spring-boot-actuator


    【解决方案1】:

    这样做是出于安全原因。某些端点可能太“脆弱”而无法在生产中暴露。

    对于开发,可以通过放置一次暴露所有端点

    management.endpoint.web.exposure.include=*
    

    另一种选择是在执行器实际启动之前分析属性的值并“以编程方式”添加端点。 根据 Spring Boot 版本,这里有许多可能的方法。

    我找到了描述选项的this SO thread

    一个有趣的选项是编写一个环境后处理器,它将分析属性并用您的自定义值覆盖,在那个 SO 线程中已经提到了这个选项。

    如何在环境后处理器中使用属性的示例可以看到here(同样来自那个 SO 线程)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多