Module bus.starter

Class AwareWebMvcConfigurer

java.lang.Object
org.miaixz.bus.spring.env.SpringEnvironmentPostProcessor
org.miaixz.bus.spring.http.AwareWebMvcConfigurer
All Implemented Interfaces:
org.springframework.boot.env.EnvironmentPostProcessor, org.springframework.core.Ordered, org.springframework.web.servlet.config.annotation.WebMvcConfigurer

public class AwareWebMvcConfigurer 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
    JSON序列化时的类型支持配置
    Sentinel请求拦截器
    protected String
    Controller的统一URL前缀

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
    构造函数,初始化autoType、prefix和handler
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addArgumentResolvers(List<org.springframework.web.method.support.HandlerMethodArgumentResolver> resolvers)
    添加自定义参数解析器到Spring MVC
    void
    addInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry)
    添加拦截器到Spring MVC配置,注册SentinelRequestHandler并指定拦截路径
    void
    configureMessageConverters(List<org.springframework.http.converter.HttpMessageConverter<?>> converters)
    配置Spring MVC的消息转换器列表,按顺序添加StringHttpMessageConverter和JSON转换器。
    void
    configurePathMatch(org.springframework.web.servlet.config.annotation.PathMatchConfigurer configurer)
    为所有Controller配置统一的URL路径前缀

    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, configureAsyncSupport, configureContentNegotiation, configureDefaultServletHandling, configureHandlerExceptionResolvers, configureViewResolvers, extendHandlerExceptionResolvers, extendMessageConverters, getMessageCodesResolver, getValidator
  • Field Details

    • autoType

      protected String autoType
      JSON序列化时的类型支持配置
    • prefix

      protected String prefix
      Controller的统一URL前缀
    • handler

      protected SentinelRequestHandler handler
      Sentinel请求拦截器
  • Constructor Details

    • AwareWebMvcConfigurer

      public AwareWebMvcConfigurer(String autoType, String prefix, SentinelRequestHandler handler)
      构造函数,初始化autoType、prefix和handler
      Parameters:
      autoType - JSON序列化时的类型支持配置
      prefix - Controller的统一URL前缀
      handler - Sentinel请求拦截器
  • Method Details

    • addInterceptors

      public void addInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry)
      添加拦截器到Spring MVC配置,注册SentinelRequestHandler并指定拦截路径
      Specified by:
      addInterceptors in interface org.springframework.web.servlet.config.annotation.WebMvcConfigurer
      Parameters:
      registry - 拦截器注册表
    • addArgumentResolvers

      public void addArgumentResolvers(List<org.springframework.web.method.support.HandlerMethodArgumentResolver> resolvers)
      添加自定义参数解析器到Spring MVC
      Specified by:
      addArgumentResolvers in interface org.springframework.web.servlet.config.annotation.WebMvcConfigurer
      Parameters:
      resolvers - 参数解析器列表
    • 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配置统一的URL路径前缀
      Specified by:
      configurePathMatch in interface org.springframework.web.servlet.config.annotation.WebMvcConfigurer
      Parameters:
      configurer - URL路径匹配配置器