弹簧启动执行器"/健康"不起作用

Kau*_*ele 6 spring-boot spring-boot-actuator

我有一个运行的Springboot应用程序,它提供URL http://localhost:8081/topics并按预期返回JSON响应.

我添加了执行器依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <scope>test</scope> </dependency>

教程中所述

但是当我击中http://localhost:8081/health它时没有给出预期的结果.它说

{ "timestamp": 1497952368055, "status": 404, "error": "Not Found", "message": "No message available", "path": "/health" }

Spring启动版本是1.5.4.RELEASE.和Java 1.8我还需要做哪些其他设置?

sam*_*vic 10

在Spring Boot 2.0.0中你必须使用/actuator/health 并在application.properties文件中添加以下行:

management.endpoint.health.show-details=always
Run Code Online (Sandbox Code Playgroud)


Shi*_*pta 6

执行以下步骤:-

  1. 将执行器依赖的范围从 更改testcompile

  2. 而不是使用/health使用/actuator/health

  3. 如果你想看到细节的健康状况,然后添加management.endpoint.health.show-details=alwaysapplication.properties file


小智 6

添加 Maven 依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

应用程序属性

management.endpoints.web.exposure.include= "*" 包括执行器上的所有端点,或者 management.endpoints.web.exposure.include= health 如果只需要健康端点


Jan*_*nar 4

在你的依赖中你已经声明了

<scope>test</scope>
Run Code Online (Sandbox Code Playgroud)

代表着

测试

此范围表示该依赖项对于应用程序的正常使用来说不是必需的,并且仅适用于测试编译和执行阶段。

如果您希望它可用于应用程序的正常使用,请将<scope>test</scope>其删除或更改为<scope>compile</scope>