一、Problemdetails
RFC 7807: RFC 7807: Problem Details for HTTP APIs
错误信息返回新格式
源码:
@Configuration(proxyBeanMethods = false) //配置过一个属性 spring.mvc.problemdetails.enabled=true @ConditionalOnProperty(prefix = "spring.mvc.problemdetails", name = "enabled", havingValue = "true") static class ProblemDetailsErrorHandlingConfiguration { @Bean @ConditionalOnMissingBean(ResponseEntityExceptionHandler.class) ProblemDetailsExceptionHandler problemDetailsExceptionHandler() { return new ProblemDetailsExceptionHandler(); } }
1、
ProblemDetailsExceptionHandler
是一个@ControllerAdvice
集中处理系统异常。2、处理以下异常。如果系统出现以下异常,会被SpringBoot支持以
RFC 7807
规范方式返回错误数据。@ExceptionHandler({ HttpRequestMethodNotSupportedException.class, //请求方式不支持 HttpMediaTypeNotSupportedException.class, HttpMediaTypeNotAcceptableException.class, MissingPathVariableException.class, MissingServletRequestParameterException.class, MissingServletRequestPartException.class, ServletRequestBindingException.class, MethodArgumentNotValidException.class, NoHandlerFoundException.class, AsyncRequestTimeoutException.class, ErrorResponseException.class, ConversionNotSupportedException.class, TypeMismatchException.class, HttpMessageNotReadableException.class, HttpMessageNotWritableException.class, BindException.class })
没有开启problemdetails
# problemdetails默认为关闭状态 spring.mvc.problemdetails.enabled=false
开启problemdetails
# problemdetails默认为关闭状态 spring.mvc.problemdetails.enabled=true
使用了新的媒体类型