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

Spring Boot配置接口WebMvcConfigurer的实现

发布时间:2022-02-25 13:01:03 所属栏目:系统 来源:互联网
导读: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 addViewControllers(ViewControllerRegistry registry);/**  *静态资源处理**/void addResourceHandlers(ResourceHandlerRegistry registry);/* 默认静态资源处理器 */void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer);/**  * 这里配置视图解析器 **/void configureViewResolvers(ViewResolverRegistry registry);/* 配置内容裁决的一些选项*/void configureContentNegotiation(ContentNegotiationConfigurer configurer);
  



(编辑:帝国网站管理系统)

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

    热点阅读