2015-09-07 38 views
3

我已經失去了自動轉發到index.html由spring-boot-starter-web啓用,因爲我改變了server.servlet.path=/spring具有在/彈簧執行器端點。春季啓動失去默認index.html改變server.servlet.path時重定向

我有一個純REST API應用程序,我使用Jersey作爲我的端點@ApplicationPath("/user),但我想使用默認/上下文重定向到index.html以獲取API文檔。

我試過在Java Spring Boot: How to map my app root (「/」) to index.html?但無濟於事指示的解決方案:

@Configuration 
public class WebMvcConfiguration { 

    @Bean 
    public WebMvcConfigurerAdapter forwardToIndex() { 
    return new WebMvcConfigurerAdapter() { 
     @Override 
     public void addViewControllers(ViewControllerRegistry registry) { 
      // redirect requests to/to index.html 
      registry.addViewController("/").setViewName("redirect:/index.html"); 
     } 
    }; 
} 

是否有可能實現嗎?

回答

1

那麼,你現在根本沒有服用/。由於您的更改,Spring Boot只能處理來自/spring的任何內容。

你的代碼實際上是要求/spring/重定向到/spring/index.html

+0

無論如何,在繼續提供默認上下文(以及其他上下文)的同時將命名空間專用於Acuator服務? – coolnodje

+2

您正在尋找['management.context-path'](http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-customizing-management-server-context -路徑)。你改變的是根servlet。 –