2015-10-27 111 views
0

我使用Spring Boot 1.2.7。增加了如下的歡迎頁面:春季啓動 - 歡迎頁

@Configuration 
public class TomcatConfig { 

    // .... 

    factory.addContextCustomizers(new TomcatContextCustomizer() { 
       @Override 
       public void customize(Context context) { 
        context.addWelcomeFile("/landingPage");     
       } 
      }); 
} 

在WebMvc,

@Configuration 
public class MvcConfig extends WebMvcConfigurerAdapter { 
    @Override 
    public void addViewControllers(ViewControllerRegistry registry) { 
     registry.addViewController("/").setViewName("landingPage"); 
     registry.setOrder(Ordered.HIGHEST_PRECEDENCE); 
     super.addViewControllers(registry); 
    } 
} 

但是,這是行不通的。我是否缺少配置?

回答

0

適合我。也許你忘了添加模板引擎f.e. Thymeleaf?

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-thymeleaf</artifactId> 
</dependency> 
0

,如果你使用的是彈簧啓動爲什麼你需要使用TomcatContextCustomizer並且已經從WebMvcConfigurerAdapter延伸覆蓋彈簧啓動的默認配置,這意味着春天開機自動配置將無法工作,因爲它是現在被你的MvcConfig類覆蓋。希望這個回答你的問題。