日常运维中,常常会遇到监控微服务状态的场景。在使用Srping Boot构建的项目中,Spring Actuator提供了开箱即用的运维端点。
使用方法非常简单,在pom文件中加入依赖如下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
上面省略了<version>标签,让Maven自动使用Spring Boot父POM中定义的版本
重新编译后,对于Srping Boot2以上的版本,访问:localhost:8012/actuator/health
会返回:{"status":"UP"}
如果是Srping Boot2以下的版本,默认是访问:http://localhost:8012/health