将多个URL路由到Spring Boot Actuator的运行状况端点

bal*_*cle 2 spring-mvc spring-boot spring-boot-actuator

我有一个应用程序配置为在/ manage/health服务Spring Boot Actuator的健康端点.不幸的是,由于我正在部署的基础设施的一些细节,我需要将/和/ health替换为/ manage/health.

我没有看到通过属性自定义健康端点URL的选项.我假设没有办法添加适用于我不拥有的控制器的额外@RequestMapping注释.

我宁愿明确定义所需的别名,而不是一些影响所有流量性能的流量拦截器.对于Spring来说相对较新,我不确定最好的方法是什么,我的搜索不会引导我朝着正确的方向前进.

谁能提供一些方向?

谢谢.

M. *_*num 10

将bean添加到配置中以添加视图控制器.这必须扩展WebMvcConfigurerAdapter并简单地覆盖该addViewControllers方法.

@Configuration
public class AliasWebConfig extends WebMvcConfigurerAdapter {

    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("forward:/manage/health");
        registry.addViewController("/health").setViewName("forward:/manage/health");
    }
}
Run Code Online (Sandbox Code Playgroud)

或者,如果您想强制使用重定向addRedirectViewController而不是addViewController.

@Configuration
public class AliasWebConfig extends WebMvcConfigurerAdapter {

    public void addViewControllers(ViewControllerRegistry registry) {
        registry. addRedirectViewController("/", "/manage/health");
        registry.addRedirectViewController("/health","/manage/health");
    }
}
Run Code Online (Sandbox Code Playgroud)