首页服务器Web服务器 Spring Boot配置接口WebMvcConfigurer的实现

Spring Boot配置接口WebMvcConfigurer的实现

WebMvcConfigurer配置类其实是Spring内部的一种配置方式,采用JavaBean的形式来代替传统的xml配置文件形式进行针对框架个性化定制。基于java-based方式的spring mvc配置,需要…

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 var1);  void addReturnValueHandlers(List var1);  void configureMessageConverters(List> var1);  void extendMessageConverters(List> var1);  void configureHandlerExceptionResolvers(List var1);  void extendHandlerExceptionResolvers(List 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);                          
本文来自网络,不代表1号站长-站长学院|资讯交流平台立场。转载请注明出处: https://www.1cn.cc/fwq/web/6889.html
上一篇web服务器,应用程序服务器,http服务器的区别是什么?
下一篇 浅谈webpack和webpack-cli模块源码分析
admin

作者: admin

这里可以再内容模板定义一些文字和说明,也可以调用对应作者的简介!或者做一些网站的描述之类的文字或者HTML!

为您推荐

评论列表()

    联系我们

    联系我们

    0898-88888888

    在线咨询: QQ交谈

    邮箱: email@wangzhan.com

    工作时间:周一至周五,9:00-17:30,节假日休息

    关注微信
    微信扫一扫关注我们

    微信扫一扫关注我们

    关注微博
    返回顶部