Spring boot interceptor WebMvcConfigurerAdapter, and a higher version of the replacement scheme
The recent project uses spring icloud, and the spring boot version is 1.5.x. WebMvcConfigurerAdapter will be cancelled after spring boot 2.0 and Spring 5.0. The following is a general introduction, I hope it will be helpful to all of you.
The following WebMvcConfigurerAdapter commonly used rewrite interfaces / * * solve cross-domain problems * * / public void addCorsMappings (CorsRegistry registry); / * * add interceptors * * / void addInterceptors (InterceptorRegistry registry); / * * configure view parsers * * / void configureViewResolvers (ViewResolverRegistry registry); / * * configure some options for content adjudication * * / void configureContentNegotiation (ContentNegotiationConfigurer configurer); / * * View Jump Controller * * / void addViewControllers (ViewControllerRegistry registry) / * * static resource processing * * / void addResourceHandlers (ResourceHandlerRegistry registry); / * default static resource processor * * / void configureDefaultServletHandling (DefaultServletHandlerConfigurer configurer); there are currently two new versions of solutions
Scenario 1 directly implements WebMvcConfigurer
@ Configurationpublic class WebMvcConfg implements WebMvcConfigurer {@ Override public void addViewControllers (ViewControllerRegistry registry) {registry.addViewController ("/ index") .setViewName ("index");}}
Scenario 2 inherits WebMvcConfigurationSupport directly
@ Configurationpublic class WebMvcConfg extends WebMvcConfigurationSupport {@ Override public void addViewControllers (ViewControllerRegistry registry) {registry.addViewController ("/ index") .setViewName ("index");}}
In fact, WebMvcConfigurerAdapter under the source code implements the WebMvcConfigurer interface, so it is possible to implement the WebMvcConfigurer interface directly. WebMvcConfigurationSupport is in the same directory as WebMvcConfigurerAdapter and interface WebMvcConfigurer. WebMvcConfigurationSupport contains the methods in WebMvcConfigurer, so it seems that the WebMvcConfigurationSupport class should be recommended in the version, and WebMvcConfigurationSupport should be the replacement and extension of WebMvcConfigurerAdapter in the new version. [personal opinion, if there is any mistake, please help correct]