开启@EnableWebMvc注解意味着springboot的mvc等自动配置失效,慎用。
建议实现接口:WebMvcConfigurer,不开启EnableWebMvc,做个性化定制。
@EnableWebMvc注解
@Import(DelegatingWebMvcConfiguration.class)
@EnableWebMvc
@Configuration(proxyBeanMethods = false)
public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport
xxx
}
开启@EnableWebMvc注解,意味着导入WebMvcConfigurationSupport。
@Configuration(proxyBeanMethods = false)
@ConditionalOnWebApplication(type = Type.SERVLET)
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class, WebMvcConfigurer.class })
@ConditionalOnMissingBean(WebMvcConfigurationSupport.class)
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE + 10)
@AutoConfigureAfter({ DispatcherServletAutoConfiguration.class, TaskExecutionAutoConfiguration.class,
ValidationAutoConfiguration.class })
public class WebMvcAutoConfiguration {
xxx
}
WebMvcAutoConfiguration只有在类WebMvcConfigurationSupport不存在时,才会生效。