Spring boot 默认首页配置

Spring boot没有了web.xml配置文件,那首页该如何设置那?

首页文件需要放到static目录下,具体项目结构如下图所示:

image

添加配置类,其代码如下:

import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class IndexViewConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("forward:/index.html");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }
}

此时通过IP+端口号,就可以访问默认首页了。

posted @ 2018-11-07 15:50  星辰大海mark-shi  阅读(14539)  评论(0编辑  收藏  举报