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

相关推荐
Jabes.yang39 分钟前
Java求职面试实战:从Spring Boot到微服务架构的技术探讨
java·数据库·spring boot·微服务·面试·消息队列·互联网大厂
聪明的笨猪猪42 分钟前
Java Redis “高可用 — 主从复制”面试清单(含超通俗生活案例与深度理解)
java·经验分享·笔记·面试
兮动人1 小时前
Spring Bean耗时分析工具
java·后端·spring·bean耗时分析工具
MESSIR221 小时前
Spring IOC(控制反转)中常用注解
java·spring
摇滚侠1 小时前
Spring Boot 3零基础教程,Demo小结,笔记04
java·spring boot·笔记
笨手笨脚の2 小时前
设计模式-迭代器模式
java·设计模式·迭代器模式·行为型设计模式
spencer_tseng3 小时前
Eclipse 4.7 ADT (Android Development Tools For Eclipse)
android·java·eclipse
聪明的笨猪猪3 小时前
Java Spring “AOP” 面试清单(含超通俗生活案例与深度理解)
java·经验分享·笔记·面试
seven97_top4 小时前
Springboot 常见面试题汇总
java·spring boot·后端
小蕾Java5 小时前
Java 开发工具,最新2025 IDEA 使用,保姆级教程
java·开发语言·intellij-idea