Module bus.starter

Class WebMvcConfigurer

All Implemented Interfaces:
org.springframework.boot.env.EnvironmentPostProcessor, org.springframework.core.Ordered, org.springframework.web.servlet.config.annotation.WebMvcConfigurer

public class WebMvcConfigurer extends SpringEnvironmentPostProcessor implements org.springframework.web.servlet.config.annotation.WebMvcConfigurer
配置 Spring MVC 消息转换器,支持字符串和 JSON 序列化/反序列化。 支持默认 JSON 框架(Jackson、Fastjson)和通过 JsonConverterConfigurer 配置的自定义框架。 确保 UTF-8 编码支持中文字符,并优雅处理缺失的依赖。 使用 bus 库的 SpringBuilder 获取自定义配置器。
Since:
Java 17+
Author:
Kimi Liu
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String
     
     
    protected String
     

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addArgumentResolvers(List<org.springframework.web.method.support.HandlerMethodArgumentResolver> resolvers)
     
    void
    addInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry)
     
    void
    configureMessageConverters(List<org.springframework.http.converter.HttpMessageConverter<?>> converters)
    配置 Spring MVC 的消息转换器列表。
    void
    configurePathMatch(org.springframework.web.servlet.config.annotation.PathMatchConfigurer configurer)
    为所有Controller配置统一前缀

    Methods inherited from class org.miaixz.bus.spring.env.SpringEnvironmentPostProcessor

    getOrder, postProcessEnvironment

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.web.servlet.config.annotation.WebMvcConfigurer

    addCorsMappings, addErrorResponseInterceptors, addFormatters, addResourceHandlers, addReturnValueHandlers, addViewControllers, configureApiVersioning, configureAsyncSupport, configureContentNegotiation, configureDefaultServletHandling, configureHandlerExceptionResolvers, configureMessageConverters, configureViewResolvers, extendHandlerExceptionResolvers, extendMessageConverters, getMessageCodesResolver, getValidator
  • Field Details

  • Constructor Details

  • Method Details

    • addInterceptors

      public void addInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry)
      Specified by:
      addInterceptors in interface org.springframework.web.servlet.config.annotation.WebMvcConfigurer
    • addArgumentResolvers

      public void addArgumentResolvers(List<org.springframework.web.method.support.HandlerMethodArgumentResolver> resolvers)
      Specified by:
      addArgumentResolvers in interface org.springframework.web.servlet.config.annotation.WebMvcConfigurer
    • configureMessageConverters

      public void configureMessageConverters(List<org.springframework.http.converter.HttpMessageConverter<?>> converters)
      配置 Spring MVC 的消息转换器列表。 按指定顺序添加 StringHttpMessageConverter 和 JSON 转换器(默认和自定义)。 确保至少一个 JSON 框架(Jackson、Fastjson 或自定义配置器)存在,否则抛出异常。
      Specified by:
      configureMessageConverters in interface org.springframework.web.servlet.config.annotation.WebMvcConfigurer
      Parameters:
      converters - 要配置的消息转换器列表
      Throws:
      IllegalStateException - 如果没有可用的 JSON 配置器
    • configurePathMatch

      public void configurePathMatch(org.springframework.web.servlet.config.annotation.PathMatchConfigurer configurer)
      为所有Controller配置统一前缀
      Specified by:
      configurePathMatch in interface org.springframework.web.servlet.config.annotation.WebMvcConfigurer
      Parameters:
      configurer - URL 路径匹配到控制器