春季启动 - 欢迎页面

时间:2015-10-27 01:19:40

标签: spring-security spring-boot

我使用的是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 );
    }
}

但是,它没有用。我错过了任何配置吗?

2 个答案:

答案 0 :(得分:0)

对我来说很好。也许你忘了添加模板引擎,f.e。 Thymeleaf?

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

答案 1 :(得分:0)

如果您使用的是spring-boot,为什么还需要使用TomcatContextCustomizer并通过从WebMvcConfigurerAdapter扩展来覆盖spring-boot的默认配置,这意味着spring boot auto配置将无法正常工作,因为它现在已被MvcConfig覆盖类。希望这能回答你的问题。