目录
一. 报错信息
二. 罪魁祸首+原理解析
2.1.处理方法
删除@EnableWebMvc这个注解就好了
@EnableWebMvc
2.2. 原因
在配置类中添加@EnableWebMvc
表示全面接管SpringMVC,SpringBoot对SpringMVC的自动配置不需要了,所有的都是我们自己配,所有默认配置都没了!有时会导致很多请求进不来,或者参数转换出错之类的,因为spring mvc默认的转换器已经不生效了,所以在大多数情况下我们需要的是在其基础配置上添加自定义配置。
2.3. 原理:
为什么@EnableWebMvc自动配置就失效了;
2.3.1)@EnableWebMvc的核心
@Import(DelegatingWebMvcConfiguration.class)
public @interface EnableWebMvc {
2.3.2)、
@Configuration
public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport {
2.3.3)、
@Configuration
@ConditionalOnWebApplication
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class,
WebMvcConfigurerAdapter.class })
//容器中没有这个组件的时候,这个自动配置类才生效
@ConditionalOnMissingBean(WebMvcConfigurationSupport.class)
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE + 10)
@AutoConfigureAfter({ DispatcherServletAutoConfiguration.class,
ValidationAutoConfiguration.class })
public class WebMvcAutoConfiguration {