三者区别:@EnableWebMvc WebMvcConfigurationSupport WebMvcConfigurerAdapter
结论: @EnableWebMvc 就是 WebMvcConfigurationSupport,但是 如果想个性化重写某些方法,请 继承 WebMvcConfigurerAdapter 重写即可。如果还是满足不了,请删除 @EnableWebMvc 后 继承 WebMvcConfigurationSupport 重写方法。
@EnableWebMvc
annotation is used there's no need to extend directly WebMvcConfigurationSupport
, and you should just extend WebMvcConfigurerAdapter
官网给出的解释 If the customization options ofWebMvcConfigurer
do not expose something you need to configure, consider removing the @EnableWebMvc annotation and extending directly fromWebMvcConfigurationSupport
overriding selected @Bean methods: @Configuration @ComponentScan(basePackageClasses = { MyConfiguration.class }) public class MyConfiguration extends WebMvcConfigurationSupport { @Override public void addFormatters(FormatterRegistry formatterRegistry) { formatterRegistry.addConverter(new MyConverter()); } @Bean public RequestMappingHandlerAdapter requestMappingHandlerAdapter() { // Create or delegate to "super" to create and // customize properties of RequestMapingHandlerAdapter } }