spring-mvc - 将多个 URL 路由到 Spring Boot Actuator 健康端点

标签 spring-mvc spring-boot spring-boot-actuator

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

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

我更愿意明确定义所需的别名,而不是一些影响所有流量性能的流量拦截器。对 Spring 来说相对较新,我不确定最好的方法是什么,我的搜索并没有把我引向正确的方向。

任何人都可以提供一些方向吗?

谢谢。

最佳答案

将 bean 添加到配置中以添加 View Controller 。这必须扩展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");
    }
}

或者如果你想强制重定向使用 addRedirectViewController而不是 addViewController .
@Configuration
public class AliasWebConfig extends WebMvcConfigurerAdapter {

    public void addViewControllers(ViewControllerRegistry registry) {
        registry. addRedirectViewController("/", "/manage/health");
        registry.addRedirectViewController("/health","/manage/health");
    }
}

关于spring-mvc - 将多个 URL 路由到 Spring Boot Actuator 健康端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32502908/

相关文章:

java - 测试 spring mvc Controller

java - spring boot : java. lang.IllegalArgumentException: 对象不是声明类的实例

spring-boot-actuator - spring cloud gateway,你能排除路径吗(做一个全局的!=)

spring-boot - Spring Boot 执行器 "/health"不工作

spring-mvc - 为什么 Kotlin 与 Spring MVC JSON 返回空对象?

spring-mvc - 在 Zuul 代理后面时,Spring 重定向 url 问题

spring-mvc - 从 Spring Controller 下载文件抛出 IllegalStateException

java - (spring boot) jar 无法在其他计算机上执行

java - Spring Data Jpa展示

spring-boot-actuator - 如何在 Spring Boot Admin UI 中启用关机功能?