Bob Lukens
Bob Lukens

Reputation: 720

How To Implement A Healthcheck in Springboot MVC Application That Waits Until Spring MVC Has Started?

I have run into an issue where a load balancer that is calling the Spring Boot healthcheck endpoint to determine if app is up receives a status of UP from Spring Boot before the Spring App is actually UP.

Is there an easy way to delay the Actuator startup until after the web app has started?

Upvotes: 0

Views: 1058

Answers (2)

nedenom
nedenom

Reputation: 415

You can listen to the application events in a custom health check implementation.

class MyHealthIndicator implements HealthIndicator, ApplicationListener<ApplicationStartedEvent> {
    boolean ready = false;

    public void onApplicationEvent(ApplicationStartedEvent event) {
        ready = true;
    }
}

But as commented above, you'll probably experience that the endpoint isn't avaliable until application has started anyway.

Upvotes: 1

Gergely Bacso
Gergely Bacso

Reputation: 14651

You actually have the option to configure special MVC healthcheck indicators.

Check this example: MVC Endpoint

@Component
public class EndpointsMvcEndpoint extends EndpointMvcAdapter {

    private final EndpointsEndpoint delegate;

Upvotes: 0

Related Questions