When I access the /health
endpoint from my Spring Boot application (1.2.4.RELEASE) it is returning a status of DOWN
:
{
status: \"DO
I had the same issue with Springboot 2.1.0 where /actuator/health returned
{
status: "DOWN"
}
even though application was up.
Adding
management.health.defaults.enabled=false
to properties file fixed the issue.
If the health url shows "DOWN" or HTTP 503 - Service Unavailable error, then try adding the below property in application.properties
URL - http://localhost:8080/actuator/health
management.endpoint.health.show-details=always
Now the url should show more than just DOWN. If Solr host is not reachable, then ignore the Solr check using the below exclusion -
@SpringBootApplication(exclude = { SolrAutoConfiguration.class })
Now the health should come up. The health check basically validates predefined health check internally (Example - DataSourceHealthIndicator, DiskSpaceHealthIndicator, CassandraHealthIndicator
, etc).
If one of the health indicator is down, the health will be down and you can see the error as a response after adding the property mentioned above to application.properties.
In your Spring properties, set endpoints.health.sensitive = false
. The /health
endpoint will then return the list of various health indicators and you can debug from there.
For a production environment you should enable security around the /health
endpoint.
Edit
As Vincent pointed out below, you'll also need management.security.enabled = false
if the health endpoint is secured, which seems to be the default in more recent versions of Spring Boot.
A common issue that I've seen with Spring Boot out of the box is that it auto-configures Solr, and without additional configuration the /health
endpoint indicates that Solr is DOWN
. An easy way to fix this is to disable the Solr auto configuration in your Application.java with this annotation:
@SpringBootApplication(exclude={SolrAutoConfiguration.class})
As per this link : https://github.com/indrabasak/spring-consul-example/blob/master/client/README.md, we should strictly used below properties to avoid below error.
management.security.enabled=false
management.health.consul.enabled=false
management.endpoint.health.show-details=, it always help to debug why the Health is DOWN , it helped me resolve my issue.
I built a filter to log the health response when it fails.
package br.gov.go.sspj.k9.util;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint;
import org.springframework.stereotype.Component;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Component
public class BadHealthCheckLogFilter implements Filter {
private @Autowired HealthMvcEndpoint hme;
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, response);
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
if (req.getRequestURI().endsWith("/health") && res.getStatus() != 200)
log.error(hme.invoke(req, null).toString());
}
@Override
public void init(FilterConfig filterConfig) {
}
@Override
public void destroy() {
}
}