
SpringMVC:注解@ControllerAdvice的工作原理
/**
* Return the list of argument resolvers to use including built-in resolvers
* and custom resolvers provided via {@link #setCustomArgumentResolvers}.
*/
private List<HandlerMethodArgumentResolver> getDefaultArgumentResolvers() {
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();
// ... 省略无关代码
resolvers.add(new RequestResponseBodyMethodProcessor(getMessageConverters()
,
this.requestResponseBodyAdvice));
// ... 省略无关代码
resolvers.add(new RequestPartMethodArgumentResolver(getMessageConverters(),
this.requestResponseBodyAdvice));
// ... 省略无关代码
resolvers.add(new HttpEntityMethodProcessor(getMessageConverters(),
this.requestResponseBodyAdvice));
// ... 省略无关代码
return resolvers;
}
#getDefaultArgumentResolvers方法用于准备RequestMappingHandlerAdapt
er执行控制器方法过程中缺省使用的HandlerMethodArgumentResolver,从上
面代码可见,requestResponseBodyAdvice会被传递给RequestResponseBody
MethodProcessor/RequestPartMethodArgumentResolver/HttpEntityMethod
Processor这三个参数解析器,不难猜测,它们在工作时会使用到该requestR
esponseBodyAdvice,但具体怎么使用,为避免过深细节影响理解,本文我们
不继续展开。
推 荐 : 超 级 全 面 的 S p r i n g B o o t 注 解 介 绍