弹簧启动器:只有一些端点工作

时间:2018-01-08 12:39:58

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

我第一次尝试使用弹簧启动器,但我注意到了:

  1. 只有在我指定版本时才有效,否则不起作用;
  2. 只有少数端点在/执行器端点响应声明的端点之间起作用。
  3. 这是我在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"}]}
    

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

    {"status":"UP"}
    

    当我要求/health它返回时:

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

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

3 个答案:

答案 0 :(得分:2)

尝试其他端点时是否尝试查看日志?它说

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是与此相关的文档的链接。

答案 1 :(得分:1)

在我的情况下,我收到 404 Whitelabel错误页面,因为只有/actuator/health/actuator/info是默认启用的唯一端点(如上所述)在Spring Boot Actuator documentation

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

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

答案 2 :(得分:0)

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

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

因此,将management.endpoints.web.exposure.include=*.添加到您的application.properties中。