Spring 默认情况下未启用引导执行器路径?

Spring Boot Actuator paths not enabled by default?

在将我的 Spring 启动应用程序更新到最新的构建快照时,我看到 none 的执行器端点默认处于启用状态。如果我在 application.properties 中指定要启用它们,它们就会出现。

1) 这种行为是故意的吗?我尝试搜索一个问题来解释它,但找不到。有人可以 link 我解决问题/文档吗?

2) 有没有办法启用所有执行器端点?我经常发现自己在开发过程中使用它们,并且不想在我的属性文件中维护它们的列表。

这个答案的两个部分:

"Is there a way to enable all the actuator endpoints?"

添加此 属性 endpoints.enabled=true 而不是使用 endpoints.info.enabled=trueendpoints.beans.enabled=true

单独启用它们

更新: for Spring Boot 2.x 相关的 属性 是:

endpoints.default.web.enabled=true

"Is this behavior intended?"

可能不会。听起来您可能已经发现了最新里程碑的问题。如果您有 Spring 引导里程碑的可重现问题,那么 Spring's advice 是 ...

Reporting Issues

Spring Boot uses GitHub’s integrated issue tracking system to record bugs and feature requests. If you want to raise an issue, please follow the recommendations below:

Before you log a bug, please search the issue tracker to see if someone has already reported the problem.

If the issue doesn’t already exist, create a new issue.

Is there a way to enable all the actuator endpoints?

使用 Spring Boot 2.2.2 版本,这对我有用:

在文件 src/main/resources/application.properties 添加:

management.endpoints.web.exposure.include=*

要检查已启用的端点,请转至 http://localhost:8080/actuator

来源:docs.spring.io

即使我们如下启用所有执行器端点 management.endpoints.web.exposure.include=*(在 YAML 的情况下,星号应该用双引号括起来作为“*”,因为星号是 YAML 语法中的特殊字符之一)

默认情况下,httptrace 执行器端点仍不会在网络中启用。需要实现 HttpTraceRepository 接口以启用 httptrace(参见 Actuator default endpoints, Actuator endpoints, Actuator httptrace)。

@Component
public class CustomHttpTraceRepository implements HttpTraceRepository {

    AtomicReference<HttpTrace> lastTrace = new AtomicReference<>();

    @Override
    public List<HttpTrace> findAll() {
        return Collections.singletonList(lastTrace.get());
    }

    @Override
    public void add(HttpTrace trace) {
        if ("GET".equals(trace.getRequest().getMethod())) {
            lastTrace.set(trace);
        }
    }
}

现在可以使用 url、

访问端点
http://localhost:port/actuator/respective-actuator-endpoint 

(示例 http://localhost:8081/actuator/httptrace)

如果属性文件中存在 management.servlet.context-path 值,则 URL 将为

http://localhost:port/<servlet-context-path>/respective-actuator-endpoint 

(示例 http://localhost:8081/management-servlet-context-path-value/httptrace)