在配置类上加上@EnableWebMvc注解会使springboot默认为springmvc扩展的功能(如视图解析器等)失效
- 首先是EnableWebMvc的源码,在注解import里导入了DelegatingWebMvcConfiguration类
- DelegatingWebMvcConfiguration的源码,该类继承了WebMvcConfigurationSupport类
- 而在springboot的自动配置机制中,关于springmvc的自动配置类是WebMvcAutoConfiguration,而这个配置类的注解@ConditionalOnMissingBean({WebMvcConfigurationSupport.class})会判断容器是否存在WebMvcConfigurationSupport类,如果存在,则当前配置类不生效;即如果容器中存在WebMvcConfigurationSupport类,则springboot关于springmvc的自动配置类不会生效。
4.在使用@EnableWebMvc注解后,springboot里关于springmvc自动配置类失效,关于springmvc仅仅可以使用基本的设置,即DelegatingWebMvcConfiguration里设置的方法;