【basepro】健康检查

健康检查(actuator)

pom

     <!--健康检查-->
     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-actuator</artifactId>
     </dependency>

配置文件

#显示以下端点
management.endpoints.web.exposure.include=health,shutdown
management.endpoint.health.show-details=always
#允许显示启用/shutdown端点
management.endpoint.shutdown.enabled=true

增加自定义可见属性

/**
*health 组件增加自定义可见属性
*/

@Component
public class CustomHealthIndicator extends AbstractHealthIndicator{
    
    
	@Value("${server.servlet.context-path:}")
	private String contextPath;
	@Value("${server.profiles.active:}")
	private String currentEnv;
	@Value("${server.application.name:}")
	private String applicationName;
	
	@Override
	protected void doHealthCheck(Health.Builder builder)throws Exception{
    
    
		builder.up().withDetail("applicationName",applicationName);
		builder.up().withDetail("currentTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		builder.up().withDetail("currentEnv",currentEnv);
		builder.up().withDetail("contextPath",contextPath);
	}
}
@Data
@Configuration
@PropertySource(value="classpath:config/common.properties")
public class EndpointProp{
    
    
}

访问路径

http://localhost:8080/actuator
http://localhost:8080/actuator/health

猜你喜欢

转载自blog.csdn.net/qq_25046005/article/details/105209333