Springboot @EnableWebMvc 注解
點(diǎn)擊上方藍(lán)色字體,選擇“標(biāo)星公眾號(hào)”
優(yōu)質(zhì)文章,第一時(shí)間送達(dá)
? 作者?|??荏苒經(jīng)十載
來(lái)源 |? urlify.cn/yUJbqi
66套java從入門到精通實(shí)戰(zhàn)課程分享
@EnableWebMvc 注解的源碼如下

可以看出,真正起作用的是DelegatingWebMvcConfiguration這個(gè)類,點(diǎn)進(jìn)去看一下這個(gè)類

這個(gè)類繼承了?WebMvcConfigurationSupport 這個(gè)類,點(diǎn)開(kāi)這個(gè)類
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 這個(gè)類,那么 springboot 對(duì)于 springmvc 的自動(dòng)配置將會(huì)失效可以看到這個(gè)類中都是一些空方法,只是保留了最基本的 MVC 的功能,并不具備其它的擴(kuò)展功能
如下:springboot 對(duì)于 mvc 模塊的配置就在 WebMvcAutoConfiguration 這個(gè)類中,如果容器中沒(méi)有?WebMvcConfigurationSupport 這個(gè)類的情況下, springboot 對(duì)于 mvc 模塊的自動(dòng)配置才會(huì)生效,而 @EnableWebMvc 注解就是向容器中添加?WebMvcConfigurationSupport 這個(gè)類,所以它會(huì)導(dǎo)致 springboot 對(duì) mvc 模塊的自動(dòng)配置失效

?
粉絲福利:實(shí)戰(zhàn)springboot+CAS單點(diǎn)登錄系統(tǒng)視頻教程免費(fèi)領(lǐng)取
???
?長(zhǎng)按上方微信二維碼?2 秒 即可獲取資料
感謝點(diǎn)贊支持下哈?
