1、引入maven依赖
org.springframework.boot
spring-boot-actuator
1.5.9.RELEASE
注意:spring-boot-actuator的具体版本号,请到https://mvnrepository.com寻找兼容自己项目中spring版本互相兼容的版本号。
2、创建配置类
@Configuration
@Import({EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class})
public class ActuatorConfig {
@Bean
public EndpointHandlerMapping endpointHandlerMapping(Collection<? extends MvcEndpoint> endpoints) {
return new EndpointHandlerMapping(endpoints);
}
@Bean
public HealthMvcEndpoint healthMvcEndpoint(HealthEndpoint delegate) {
return new HealthMvcEndpoint(delegate, false);
}
}
3、访问http://{host}:port/health 即可得到健康检查结果