springboot配置WebMvcConfigurationSupport

一、在spring里有四个mvc配置类

1、mvc配置类

WebMvcConfigurer

WebMvcConfigurerAdapter

WebMvcConfigurationSupport

WebMvcAutoConfiguration

2、WebMvcConfigurer为接口

3、WebMvcConfigurerAdapter是WebMvcConfigurer的实现类,且大部分为空方法,由于Java8中可以使用default关键字为接口添加默认方法,所以在spring5.0之后就已经弃用本类

4、WebMvcConfigurationSupport是mvc的基本实现,并包含了WebMvcConfigurer接口中的方法

5、WebMvcAutoConfiguration提供默认配置属性

二、配置mvc

1、方式1:继承WebMvcConfigurationSupport类

2、方式2:如果想保持springboot mvc的默认配置,并且自定义更多的mvc配置,如:interceptors、formatters、view controllers等。可以添加@Configuration注解到一个类上,再让这个类继承WebMvcConfigurer接口,并不要标注@EnableWebMvc

3、方式3:如果想全面接管Spring mvc,继承WebMvcConfigurer接口,多加一个@EnableWebMvc注解

@EnableWebMvc表示完全自己控制mvc配置,也就是说所有配置自己重写,所有默认配置都没了

参考资料:

https://blog.csdn.net/qq_33286757/article/details/131665352

相关推荐
李白的粉15 分钟前
基于springboot的新闻资讯系统
java·spring boot·毕业设计·课程设计·源代码·新闻资讯系统
麦麦鸡腿堡15 分钟前
Java_LinkedList底层结构
java·开发语言
whatever who cares23 分钟前
android/java中gson的用法
android·java·开发语言
摇滚侠26 分钟前
Spring Boot3零基础教程,为什么有Reactive-Stream 规范,响应式编程,笔记101
java·spring boot·笔记
天天摸鱼的java工程师41 分钟前
八年 Java 开发手敲:SpringBoot+SpringSecurity+JWT 实战,前后分离权限注解落地就能跑
java·后端
冰淇淋@43 分钟前
idea启动项目报错java: OutOfMemoryError: insufficient memory
java·ide·intellij-idea
techzhi1 小时前
this view is read-only (IntelliJ IDEA)
java·ide·intellij-idea
编程学委1 小时前
Idea(2023版)使用Svn
java·svn·intellij-idea
qianbailiulimeng1 小时前
IDEA + Spring Boot 的三种热加载方案
java·后端
王元_SmallA1 小时前
网卡驱动架构以及源码分析
java·后端