Springboot @EnableWebMvc 注解
@EnableWebMvc 注解的源码如下
可以看出,真正起作用的是DelegatingWebMvcConfiguration这个类,点进去看一下这个类
这个类继承了 WebMvcConfigurationSupport 这个类,点开这个类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public class WebMvcConfigurationSupport implements ApplicationContextAware, ServletContextAware { protected void configureContentNegotiation(ContentNegotiationConfigurer configurer) { } protected void configureContentNegotiation(ContentNegotiationConfigurer configurer) { } protected void configureContentNegotiation(ContentNegotiationConfigurer configurer) { } protected void addViewControllers(ViewControllerRegistry registry) { } .... } |
可以看到这个类中都是一些空方法,只是保留了最基本的 MVC 的功能,并不具备其它的扩展功能
并且如果容器中存在 WebMvcConfigurationSupport 这个类,那么 springboot 对于 springmvc 的自动配置将会失效
如下:springboot 对于 mvc 模块的配置就在 WebMvcAutoConfiguration 这个类中,如果容器中没有 WebMvcConfigurationSupport 这个类的情况下, springboot 对于 mvc 模块的自动配置才会生效,而 @EnableWebMvc 注解就是向容器中添加 WebMvcConfigurationSupport 这个类,所以它会导致 springboot 对 mvc 模块的自动配置失效
分类:
Spring 常用注解
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?