异常解析器默认配置public class WebMvcAutoConfiguration {@Configuration(proxyBeanMethods = false)@EnableConfigurationProperties(WebProperties.class)public static class EnableWebMvcConfiguration extends DelegatingWebMvcConfiguration {}}public class WebMvcConfigurationSupport {@Beanpublic HandlerExceptionResolver handlerExceptionResolver(@Qualifier("mvcContentNegotiationManager") ContentNegotiationManager contentNegotiationManager) {List<HandlerExceptionResolver> exceptionResolvers = new ArrayList<>();// 处理自定义异常解析器的配置configureHandlerExceptionResolvers(exceptionResolvers);if (exceptionResolvers.isEmpty()) {// 如果没有异常解析器,那么添加默认的异常解析器addDefaultHandlerExceptionResolvers(exceptionResolvers, contentNegotiationManager);}extendHandlerExceptionResolvers(exceptionResolvers);HandlerExceptionResolverComposite composite = new HandlerExceptionResolverComposite();// 设置高优先级,Composite成为统一的入口composite.setOrder(0);composite.setExceptionResolvers(exceptionResolvers);return composite;}// 默认配置protected final void addDefaultHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers, ContentNegotiationManager mvcContentNegotiationManager) {ExceptionHandlerExceptionResolver exceptionHandlerResolver = createExceptionHandlerExceptionResolver();exceptionHandlerResolver.setContentNegotiationManager(mvcContentNegotiationManager);exceptionHandlerResolver.setMessageConverters(getMessageConverters());exceptionHandlerResolver.setCustomArgumentResolvers(getArgumentResolvers());exceptionHandlerResolver.setCustomReturnValueHandlers(getReturnValueHandlers());if (jackson2Present) {exceptionHandlerResolver.setResponseBodyAdvice(Collections.singletonList(new JsonViewResponseBodyAdvice()));}if (this.applicationContext != null) {exceptionHandlerResolver.setApplicationContext(this.applicationContext);}exceptionHandlerResolver.afterPropertiesSet();exceptionResolvers.add(exceptionHandlerResolver);ResponseStatusExceptionResolver responseStatusResolver = new ResponseStatusExceptionResolver();responseStatusResolver.setMessageSource(this.applicationContext);exceptionResolvers.add(responseStatusResolver);exceptionResolvers.add(new DefaultHandlerExceptionResolver());}}
完毕!!!
推荐阅读
- Spring Boot配置文件详解
- 地球最内核是什么?国际最新研究称或为半径约650千米铁球
- 苹果核战记1高清在线?苹果核战记度云资源,只要资源不要告诉我怎么下。?
- 快速借钱无需审核 过程审核
- 简历上怎么写个人核心竞争力 核心能力
- 日本福岛核泄漏纪录片 2011日本核泄漏
- 酸枣核和凤眼的区别
- 海鲜怎么做核算?海鲜做法?
- 中国核潜艇速度有多快 核潜艇速度
- 辩证唯物主义三大观点 唯物辩证法的核心是