Springboot 2.0 Health 인터페이스 상태 제어
Health 인터페이스, 내부 에 디자인 이 실현 되 었 습 니 다. helh 인터페이스의 status 가 UP 가 아 닐 때 helh 인터페이스 에 방문 하 는 http 상태 코드 는 503 입 니 다. 이 방식 도 좋 습 니 다. 일부 도구 에 있어 (예 를 들 어 nginx 건강 검사) 가 편리 합 니 다. 상태 코드 를 통 해 서비스 건강 상 태 를 알 수 있 기 때 문 입 니 다.그러나 가끔 은 헬 스 인터페이스의 반환 내용 을 통 해 실제 상 태 를 판단 하고 싶 습 니 다. 이 럴 때 상태 코드 가 200 이 아니라면 분석 요청 에 영향 을 줄 수 있 습 니 다.
우 리 는 다음 코드 를 통 해 helh 인터페이스의 status 와 http 상태 코드 의 관 계 를 정의 할 수 있 습 니 다.
@Bean
@ConditionalOnProperty("management.health.status.static")
public HealthStatusHttpMapper healthStatusHttpMapper() {
HealthStatusHttpMapper healthStatusHttpMapper = new HealthStatusHttpMapper();
healthStatusHttpMapper.addStatusMapping(Status.DOWN,WebEndpointResponse.STATUS_OK);
healthStatusHttpMapper.addStatusMapping(Status.UNKNOWN,WebEndpointResponse.STATUS_OK);
healthStatusHttpMapper.addStatusMapping(Status.OUT_OF_SERVICE,WebEndpointResponse.STATUS_OK);
return healthStatusHttpMapper;
}