Springboot @EnableWebMvc 注解

java1234

共 1208字,需浏览 3分钟

 · 2020-11-22

点击上方蓝色字体,选择“标星公众号”

优质文章,第一时间送达

  作者 |  荏苒经十载

来源 |  urlify.cn/yUJbqi

66套java从入门到精通实战课程分享

@EnableWebMvc 注解的源码如下

可以看出,真正起作用的是DelegatingWebMvcConfiguration这个类,点进去看一下这个类

这个类继承了 WebMvcConfigurationSupport 这个类,点开这个类

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) {
    }
    ....
}


并且如果容器中存在  WebMvcConfigurationSupport 这个类,那么 springboot 对于 springmvc 的自动配置将会失效可以看到这个类中都是一些空方法,只是保留了最基本的 MVC 的功能,并不具备其它的扩展功能

如下:springboot 对于 mvc 模块的配置就在 WebMvcAutoConfiguration 这个类中,如果容器中没有 WebMvcConfigurationSupport 这个类的情况下, springboot 对于 mvc 模块的自动配置才会生效,而 @EnableWebMvc 注解就是向容器中添加 WebMvcConfigurationSupport 这个类,所以它会导致 springboot 对 mvc 模块的自动配置失效

 





粉丝福利:实战springboot+CAS单点登录系统视频教程免费领取

???

?长按上方微信二维码 2 秒
即可获取资料



感谢点赞支持下哈 

浏览 24
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报