目录
3.继承WebMvcConfigurationSupport导致静态资源无法访问
4.WebMvcAutoConfiguration Did not match,webmvcAutoConfiguration配置没有加载
5.ThymeleafAutoConfiguration加载条件
1.实现无业务逻辑跳转
有的时候时候我们只需要一个业务逻辑的跳转,这时候我们会在Controller中写一个跳转的方法,如下图所示。但是每次需要跳转都需要一个方法太麻烦也不便于管理,于是就有了WebMvcConfigurerAdapter类。
@RequestMapping("/")
public String index(){
return "login";
}
2.WebMvcConfigurerAdapter方法过时
但是自从Spring Boot2.0的版本之后这个方法就过时了,由以下两种方法来实现。
①implements WebMvcConfigurer(官方推荐)
②extends WebMvcConfigurationSupport
/
* @deprecated as of 5.0 {@link WebMvcConfigurer} has default methods (made
* possible by a Java 8 baseline) and can be implemented directly without the
* need for this adapter
*/
@Configuration
public class MyMvcConfigNew extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("login");
}
}