Spring Boot default page
Spring Boot default welcome screen is the main / resources / static / index.html.
Spring Boot modify the default page
The original WebMvcConfigurerAdapter have become obsolete, replaced by inheritance WebMvcConfigurationSupport class or implement WebMvcConfigurer interface.
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.WebMvcConfigurationSupport;
@Configuration
public class DefaultViewConfig extends WebMvcConfigurationSupport {
@Override
public void addViewControllers(ViewControllerRegistry registry){
//设置访问路径为 “/”
registry.addViewController("/").setViewName("login.html");
//设置为最高优先级
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
super.addViewControllers(registry);
}
}
By writing the configuration classes, inheritance WebMvcConfigurationSupport class, override addViewController () method.
registry.addViewController("/").setViewName("login.html");
This code corresponds to
@Controller
public class TestController{
@RequestMapping("/")
public String testController(){
return "login";
}
}
Browser to access http: // localhost: 8080 / can access the main / resources / static / login.html.