Dear developers,
When using a custom HandlerMethodArgumentResolver recently discovered that he did not take effect, I found after tracking code custom HandlerMethodArgumentResolver always cannot be invoked, because his priority, after the system default ArgumentResolver can never be called, Please see the detailed code HandlerMethodArgumentResolverComposite class getArgumentResolver (MethodParameter parameter) method, my code is as follows:
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
resolvers.add(new HandlerMethodArgumentResolver() {
@Override
public boolean supportsParameter(MethodParameter parameter) {
log.debug("测试参数转换是否生效");
return parameter.getParameterName().equals("token")
|| parameter.getParameterType().isInstance(TokenSupplierCode.class);
}
It has always been higher priority RequestResponseBodyMethodProcessor execution
Comment From: rstoyanchev
This is indeed expected. Custom resolvers are ordered after built-in ones. Is this on an @RequestBody argument? What are you trying to do?
Comment From: tri5m
This is indeed expected. Custom resolvers are ordered after built-in ones. Is this on an
@RequestBodyargument? What are you trying to do?
Thank you for your reply to my message, I did use the error, I did use @requestbody, I understand there was an error, thought the custom handler would overwrite @requestbody, temporarily removed the @requestbody annotation took effect, but some plug-ins that rely on @requestbody annotation cannot be used, such as Swagger.
Comment From: tri5m
I want to use a custom parameter handler to solve the problem of getting some fields from an object and processing them, and then continue to use the reqeustBody handler to perform the default processing. I have now completed this requirement with the custom parameter validate.
However, I can now implement the previous requirement using custom annotations, recalling the @requestbody handler in the custom handler.
Comment From: rstoyanchev
Maybe what you're looking for is RequestBodyAdvice.