Spring Boot Actuator Health Returning DOWN

后端 未结 12 1054
面向向阳花
面向向阳花 2021-01-31 02:49

When I access the /health endpoint from my Spring Boot application (1.2.4.RELEASE) it is returning a status of DOWN:

{
    status: \"DO         


        
12条回答
  •  粉色の甜心
    2021-01-31 03:11

    I got this fixed using below code.

    Wrote a controller which accepts "/private/health" mapping (You can use /health instead).

    import io.swagger.annotations.Api;
    import org.springframework.http.HttpStatus;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseStatus;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @RequestMapping
    @Api(value = "Heath Service Health", description = "Heath Service Health")
    public class HeathController {
      @GetMapping(value = "/private/health")
      @ResponseStatus(HttpStatus.OK)
      HealthStatusDto healthCheck() {
        return HealthStatusDto.builder().status("UP").build();
      }
    }
    

    Below class is optional. Instead of returning HealthStatusDto in above controller you can return any other message as a String.

    import lombok.AllArgsConstructor;
    import lombok.Builder;
    import lombok.Data;
    
    @Data
    @AllArgsConstructor
    @Builder
    public final class HealthStatusDto {
      private final String status;
    }
    

    Add below config in application.yml

    # actuator
    # Disable Spring security
    management:
      security:
        enabled: false
    
    # Disable actuators
    endpoints:
      actuator:
        enabled: false
      enabled: false
    

    Hope this helps

提交回复
热议问题