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
FieldsModifier and TypeFieldDescriptionprotected StringJSON序列化时的类型支持配置protected SentinelRequestHandlerSentinel请求拦截器protected StringController的统一URL前缀Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionAwareWebMvcConfigurer(String autoType, String prefix, SentinelRequestHandler handler) 构造函数,初始化autoType、prefix和handler -
Method Summary
Modifier and TypeMethodDescriptionvoidaddArgumentResolvers(List<org.springframework.web.method.support.HandlerMethodArgumentResolver> resolvers) 添加自定义参数解析器到Spring MVCvoidaddInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry) 添加拦截器到Spring MVC配置,注册SentinelRequestHandler并指定拦截路径voidconfigureMessageConverters(List<org.springframework.http.converter.HttpMessageConverter<?>> converters) 配置Spring MVC的消息转换器列表,按顺序添加StringHttpMessageConverter和JSON转换器。voidconfigurePathMatch(org.springframework.web.servlet.config.annotation.PathMatchConfigurer configurer) 为所有Controller配置统一的URL路径前缀Methods inherited from class org.miaixz.bus.spring.env.SpringEnvironmentPostProcessor
getOrder, postProcessEnvironmentMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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
JSON序列化时的类型支持配置 -
prefix
Controller的统一URL前缀 -
handler
Sentinel请求拦截器
-
-
Constructor Details
-
AwareWebMvcConfigurer
构造函数,初始化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:
addInterceptorsin interfaceorg.springframework.web.servlet.config.annotation.WebMvcConfigurer- Parameters:
registry- 拦截器注册表
-
addArgumentResolvers
public void addArgumentResolvers(List<org.springframework.web.method.support.HandlerMethodArgumentResolver> resolvers) 添加自定义参数解析器到Spring MVC- Specified by:
addArgumentResolversin interfaceorg.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:
configureMessageConvertersin interfaceorg.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:
configurePathMatchin interfaceorg.springframework.web.servlet.config.annotation.WebMvcConfigurer- Parameters:
configurer- URL路径匹配配置器
-