加入收藏 | 设为首页 | 会员中心 | 我要投稿 大连站长网 (https://www.0411zz.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 系统 > 正文

Spring Boot配置接口WebMvcConfigurer的完成

发布时间:2021-12-14 14:45:44 所属栏目:系统 来源:互联网
导读:WebMvcConfigurer配置类其实是Spring内部的一种配置方式,采用JavaBean的形式来代替传统的xml配置文件形式进行针对框架个性化定制。基于java-based方式的spring mvc配置,需要创建一个配置类并实现WebMvcConfigurer 接口,WebMvcConfigurerAdapter 抽象类是
WebMvcConfigurer配置类其实是Spring内部的一种配置方式,采用JavaBean的形式来代替传统的xml配置文件形式进行针对框架个性化定制。基于java-based方式的spring mvc配置,需要创建一个配置类并实现WebMvcConfigurer 接口,WebMvcConfigurerAdapter 抽象类是对WebMvcConfigurer接口的简单抽象(增加了一些默认实现),但在在SpringBoot2.0及Spring5.0中WebMvcConfigurerAdapter已被废弃 。官方推荐直接实现WebMvcConfigurer或者直接继承WebMvcConfigurationSupport,方式一实现WebMvcConfigurer接口(推荐),方式二继承WebMvcConfigurationSupport类,具体实现可看这篇文章。https://www.jb51.net/article/174766.htm
 
//// Source code recreated from a .class file by IntelliJ IDEA// (powered by Fernflower decompiler)// package org.springframework.web.servlet.config.annotation; import java.util.List;import org.springframework.format.FormatterRegistry;import org.springframework.http.converter.HttpMessageConverter;import org.springframework.validation.MessageCodesResolver;import org.springframework.validation.Validator;import org.springframework.web.method.support.HandlerMethodArgumentResolver;import org.springframework.web.method.support.HandlerMethodReturnValueHandler;import org.springframework.web.servlet.HandlerExceptionResolver; public interface WebMvcConfigurer { void configurePathMatch(PathMatchConfigurer var1);  void configureContentNegotiation(ContentNegotiationConfigurer var1);  void configureAsyncSupport(AsyncSupportConfigurer var1);  void configureDefaultServletHandling(DefaultServletHandlerConfigurer var1);  void addFormatters(FormatterRegistry var1);  void addInterceptors(InterceptorRegistry var1);  void addResourceHandlers(ResourceHandlerRegistry var1);  void addCorsMappings(CorsRegistry var1);  void addViewControllers(ViewControllerRegistry var1);  void configureViewResolvers(ViewResolverRegistry var1);  void addArgumentResolvers(List<HandlerMethodArgumentResolver> var1);  void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> var1);  void configureMessageConverters(List<HttpMessageConverter<?>> var1);  void extendMessageConverters(List<HttpMessageConverter<?>> var1);  void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> var1);  void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> var1);  Validator getValidator();  MessageCodesResolver getMessageCodesResolver();}
接下来我们着重找几个方法讲解一下:
 
 /* 拦截器配置 */void addInterceptors(InterceptorRegistry var1);/* 视图跳转控制器 */void addV

(编辑:大连站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!