Spring Boot Actuator的"/health"端点无法工作。

11

我有一个正在运行的Springboot应用程序,服务于URLhttp://localhost:8081/topics并正常返回JSON响应。

我添加了actuator依赖项

<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 boot版本为1.5.4.RELEASE。和Java 1.8 我需要做什么额外的设置?

6个回答

25
在Spring Boot 2.0.0中,您需要使用/actuator/health并在application.properties文件中添加以下行:
management.endpoint.health.show-details=always

8
请按以下步骤操作: - 将执行器依赖的范围从“test”更改为“compile” - 使用“/actuator/health”代替“/health” - 如果想要查看健康状态的详细信息,请在“application.properties”文件中添加“management.endpoint.health.show-details=always”。

6

添加Maven依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

应用程序配置文件

management.endpoints.web.exposure.include= "*" 包含所有actuator端点 或者 management.endpoints.web.exposure.include= health 仅需要健康检查端点时使用


4
在你的依赖中,你声明了
<scope>test</scope>

这意味着

测试

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

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


此外,您需要禁用Spring安全性以访问某些执行器端点。 - visrahane
1
执行器健康检查现已移至端点/actuator/health。请参阅https://github.com/spring-cloud/spring-cloud-consul/issues/345 - srgsanky

0
如果还不能工作,请按照以下步骤操作:
  1. 选择项目,右键点击
  2. 作为Maven构建运行
  3. 目标 - 清理安装,然后确定

0

Maven依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Application.properties

spring.profiles.active=local
server.port = 9292
management.endpoints.web.exposure.include=env,health,metrics

请参考以下链接(逐步解释):

https://www.youtube.com/watch?v=0Dj2tsK2V2g


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接