【问题标题】:Spring-boot actuator: only some endpoints workSpring-boot actuator:只有一些端点工作
【发布时间】:2018-06-17 10:40:24
【问题描述】:

我第一次尝试实现 spring-boot 执行器,但我注意到:

  1. 只有在我指定版本时才有效,否则无效;
  2. /actuator 端点响应声明的端点中只有少数端点有效。

这是我在 pom.xml 中插入的依赖项

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
        <version>1.4.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-actuator-docs</artifactId>
    </dependency>
    ...
</dependencies>

这是我的 application.properties:

#info for Spring Boot Actuator
info.app.name=Spring Sample Application
info.app.description=Application to demonstrate Spring REST HATEOAS and Actuator
info.app.version=1.0.0

当我发出这个 http 请求时:

http://localhost:8080/actuator

它返回我:

{"links":[{"rel":"self","href":"http://localhost:8080/actuator"},{"rel":"loggers","href":"http://localhost:8080/loggers"},{"rel":"env","href":"http://localhost:8080/env"},{"rel":"info","href":"http://localhost:8080/info"},{"rel":"heapdump","href":"http://localhost:8080/heapdump"},{"rel":"mappings","href":"http://localhost:8080/mappings"},{"rel":"metrics","href":"http://localhost:8080/metrics"},{"rel":"configprops","href":"http://localhost:8080/configprops"},{"rel":"autoconfig","href":"http://localhost:8080/autoconfig"},{"rel":"beans","href":"http://localhost:8080/beans"},{"rel":"auditevents","href":"http://localhost:8080/auditevents"},{"rel":"trace","href":"http://localhost:8080/trace"},{"rel":"health","href":"http://localhost:8080/health"},{"rel":"dump","href":"http://localhost:8080/dump"},{"rel":"docs","href":"http://localhost:8080/docs"}]}

在这些链接中,似乎只有 /health/info 有效。 事实上,当我请求 /health 时,它会返回:

{"status":"UP"}

当我要求 /info 它返回:

{"app":{"description":"Application to demonstrate Spring REST HATEOAS and Actuator","name":"Spring Sample Application","version":"1.0.0"}}

为什么所有其他端点都给了我Whitelabel 错误页面

【问题讨论】:

  • 对于初学者,请停止混合框架的版本。从spring-boot-starter-actuator 中删除&lt;version&gt; 标记以获得正确的标记。
  • 我已经介绍了这个问题,只是说我不明白为什么没有 标签就不能工作,因为它是由 Spring Initializr 自动生成的。
  • 它应该可以在没有版本的情况下工作(否则你正在以错误的方式构建),如果你选择包含一个版本,则不要混合框架的版本(无论框架如何)。跨度>

标签: spring rest spring-boot endpoint spring-boot-actuator


【解决方案1】:

您在尝试其他端点时是否尝试查看日志。它说

Full authentication is required to access actuator endpoints. Consider adding Spring Security or set 'management.security.enabled' to false.

我想这是不言自明的。至少配置基本身份验证或将上述属性设置为false

您看到的 Whitelabel 错误页面也显示

 There was an unexpected error (type=Unauthorized, status=401).  

Here 是与此相关的文档的链接。

【讨论】:

    【解决方案2】:

    在我的情况下,我得到 404 Whitelabel 错误页面,因为只有 /actuator/health/actuator/info 是默认启用的唯一端点(如 @987654321 中所述@)

    为了启用其他端点,我最终将此配置添加到我的application.yml

    management:
      endpoints:
        web:
          exposure:
            include: info, health, loggers, logfile, configprops
    

    【讨论】:

      【解决方案3】:

      我在 Baeldung 找到了一个帖子,上面写着

      与以前的版本不同,Actuator 禁用了大多数端点。 (Link)

      所以将management.endpoints.web.exposure.include=*. 添加到您的application.properties

      【讨论】:

        猜你喜欢
        • 2016-06-01
        • 2020-09-15
        • 2016-09-07
        • 2021-04-24
        • 2020-06-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-23
        相关资源
        最近更新 更多