- Spring Boot 中的 @EnableWebMvc
- SpringBoot 项目 @EnableWebMvc 和@EnableAutoConfiguration注解一些坑总结_Code_Flyer的博客-CSDN博客
自动装配了很多默认的东西,比如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配置类
WebMvcAutoConfiguration
WebMvcAutoConfiguration要判断是否存在WebMvcConfigurationSupport
WebMvcAutoConfiguration又引入EnableWebMvcConfiguration
EnableWebMvcConfiguration extends DelegatingWebMvcConfiguration
等于WebMvcAutoConfiguration又引入了DelegatingWebMvcConfiguration。