WebMvcConfigurationSupport、WebMvcConfigurer、@EnableWebMvc
问题:为什么继承了WebMvcConfigurationSupport后有些配置会不生效呢?WebMvcConfigurer又是什么呢?
简介:
SpringBoot帮我们做了很多的事情,但是有的时候会有自定义的Handler,Interceptor,ViewResolver,MessageConverter等,该怎么配置呢?为什么继承了WebMvcConfigurationSupport后有些配置会不生效呢?WebMvcConfigurer又是什么呢?我们继承WebMvcConfigurationSupport可以自定义SpringMvc的配置。
SpringBoot帮我们做了很多的事情,但是有的时候会有自定义的Handler,Interceptor,ViewResolver,MessageConverter等,该怎么配置呢?为什么继承了WebMvcConfigurationSupport后有些配置会不生效呢?WebMvcConfigurer又是什么呢?
1、WebMvcConfigurationSupport
我们继承WebMvcConfigurationSupport可以自定义SpringMvc的配置。
跟踪发现DelegatingWebMvcConfiguration类是WebMvcConfigurationSupport的一个实现类,DelegatingWebMvcConfiguration类的setConfigurers方法可以收集所有的WebMvcConfigurer实现类中的配置组合起来,组成一个超级配置(这些配置会覆盖掉默认的配置)。而@EnableWebMvc又引入了DelegatingWebMvcConfiguration。
什么是DelegatingWebMvcConfiguration?
DelegatingWebMvcConfiguration是对Spring MVC进行配置的一个代理类。它结合缺省配置和用户配置定义Spring MVC运行时最终使用的配置。
private final WebMvcConfigurerComposite configurer