java.lang.Object
org.miaixz.bus.spring.env.SpringEnvironmentPostProcessor
org.miaixz.bus.spring.web.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
FieldsModifier and TypeFieldDescriptionprotected Stringprotected SentinelRequestHandlerprotected StringFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionWebMvcConfigurer(String autoType, String prefix, SentinelRequestHandler handler) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddArgumentResolvers(List<org.springframework.web.method.support.HandlerMethodArgumentResolver> resolvers) voidaddInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry) voidconfigureMessageConverters(List<org.springframework.http.converter.HttpMessageConverter<?>> converters) 配置 Spring MVC 的消息转换器列表。voidconfigurePathMatch(org.springframework.web.servlet.config.annotation.PathMatchConfigurer configurer) 为所有Controller配置统一前缀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, configureApiVersioning, configureAsyncSupport, configureContentNegotiation, configureDefaultServletHandling, configureHandlerExceptionResolvers, configureMessageConverters, configureViewResolvers, extendHandlerExceptionResolvers, extendMessageConverters, getMessageCodesResolver, getValidator
-
Field Details
-
autoType
-
prefix
-
handler
-
-
Constructor Details
-
WebMvcConfigurer
-
-
Method Details
-
addInterceptors
public void addInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry) - Specified by:
addInterceptorsin interfaceorg.springframework.web.servlet.config.annotation.WebMvcConfigurer
-
addArgumentResolvers
public void addArgumentResolvers(List<org.springframework.web.method.support.HandlerMethodArgumentResolver> resolvers) - Specified by:
addArgumentResolversin interfaceorg.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:
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配置统一前缀- Specified by:
configurePathMatchin interfaceorg.springframework.web.servlet.config.annotation.WebMvcConfigurer- Parameters:
configurer- URL 路径匹配到控制器
-