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.
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");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With