image.png

自动装配了很多默认的东西,比如RequestMappingHandlerMapping。

  • 无论是使用@EnableWebMvc还是扩展WebMvcConfigurationSupport类,spring都会创建一个WebMvcConfigurationSupport的类,进而屏蔽掉自动装配类WebMvcAutoConfiguration。
  • 如果想保留SpringBoot的自动配置WebMvcAutoConfiguration使用implements WebMvcConfigurer。

结论:配置使用WebMvcConfigurer


org.springframework.web.servlet.config.annotation.EnableWebMvc
org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration

  • @EnableWebMvc是SpringMVC的产物代替,相当于
  • WebMvcAutoConfiguration属于SpringBoot的自动装配

@EnableAutoConfiguration自动spi获取EnableAutoConfiguration配置类

image.png
image.png
其中包括WebMvcAutoConfiguration

WebMvcAutoConfiguration

image.png
WebMvcAutoConfiguration要判断是否存在WebMvcConfigurationSupport
WebMvcAutoConfiguration又引入EnableWebMvcConfiguration
image.png

EnableWebMvcConfiguration extends DelegatingWebMvcConfiguration

等于WebMvcAutoConfiguration又引入了DelegatingWebMvcConfiguration

@EnableWebMvc加载DelegatingWebMvcConfiguration(WebMvcConfigurationSupport)

image.png

DelegatingWebMvcConfiguration(WebMvcConfigurationSupport)

image.png