2015-09-10 82 views
0

我有一個應用程序配置爲在/ manage/health上爲Spring Boot Actuator的健康端點提供服務。不幸的是,由於我正在部署的基礎設施的一些細節,我需要將/和/ health替換爲/ manage/health。將多個URL路由到Spring Boot Actuator的健康端點

我沒有看到通過屬性僅定製健康端點URL的選項。我假設沒有辦法添加適用於我不擁有的控制器的額外@RequestMapping註釋。

我寧願顯式定義所需的別名,而不是某些影響所有流量性能的流量攔截器。對於Spring來說相對較新,我不確定最好的方式是繼續進行,而我的搜索並沒有帶領我朝着正確的方向前進。

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

謝謝。

+0

爲這些URL配置視圖控制器,並轉發或重定向到正確的URL。 –

回答

6

將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"); 
    } 
} 

或者,如果你想強制重定向使用addRedirectViewController代替addViewController

@Configuration 
public class AliasWebConfig extends WebMvcConfigurerAdapter { 

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

感謝您的快速回復! – balduncle

+0

@M。 Deinum是否有可能取代重新啓動網址?可以用/ myRestart說。我想在之前執行一些操作,然後重新啓動 – gstackoverflow

相關問題