Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routing multiple URLs to Spring Boot Actuator's health endpoint

I have an app configured to serve Spring Boot Actuator's health endpoint at /manage/health. Unfortunately due to some details of the infrastructure I'm deploying to I need to alias both / and /health over to /manage/health.

I don't see an option to customize just the health endpoint URL via properties. I'm assuming there's no way to add extra @RequestMapping annotations that apply to a controller I don't own.

I'd prefer to explicitly define the required aliases as opposed to some traffic interceptor that affects the performance of all traffic. Being relatively new to Spring, I'm unsure what the best way is to proceed and my searches aren't leading me in the right direction.

Can anyone provide some direction?

Thanks.

like image 430
balduncle Avatar asked Dec 15 '22 12:12

balduncle


1 Answers

Add a bean to the configuration to add a view controller. This been must extend WebMvcConfigurerAdapter and simply override the addViewControllers method.

@Configuration
public class AliasWebConfig extends WebMvcConfigurerAdapter {

    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("forward:/manage/health");
        registry.addViewController("/health").setViewName("forward:/manage/health");
    }
}

Or if you want to force a redirect use addRedirectViewController instead of addViewController.

@Configuration
public class AliasWebConfig extends WebMvcConfigurerAdapter {

    public void addViewControllers(ViewControllerRegistry registry) {
        registry. addRedirectViewController("/", "/manage/health");
        registry.addRedirectViewController("/health","/manage/health");
    }
}
like image 128
M. Deinum Avatar answered Dec 28 '22 07:12

M. Deinum