Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Spring boot interceptor WebMvcConfigurerAdapter, and a higher version of the replacement scheme

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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]

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report