springboot 健康检查
时间: 2023-11-25 22:52:28 浏览: 50
Spring Boot提供了一个名为Actuator的子项目,它提供了许多用于监视和管理Spring Boot应用程序的端点(endpoint)。其中,/health端点用于检查应用程序的健康状况。默认情况下,/health端点返回一个简单的JSON响应,指示应用程序是否处于“UP”状态。以下是实现Spring Boot健康检查的步骤:
1.在pom.xml文件中添加以下依赖项:
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
```
2.在application.properties文件中添加以下配置:
```properties
management.endpoint.health.show-details=always
```
3.启动应用程序并访问/health端点:
```shell
curl http://localhost:8080/actuator/health
```
4.如果应用程序处于“UP”状态,则会收到以下响应:
```json
{
"status": "UP",
"details": {
"diskSpace": {
"status": "UP",
"details": {
"total": 499963170816,
"free": 416926064128,
"threshold": 10485760
}
},
"ping": {
"status": "UP"
}
}
}
```