Avoid duplicate registration of [RequestBody|ResponseBody]Advice
Prior to this commit, if a @ControllerAdvice bean implemented both RequestBodyAdvice and ResponseBodyAdvice, it was registered twice in RequestMappingHandlerAdapter, leading to duplicate application of the same logic. This commit ensures that such instances are only registered once. Fixes gh-22638
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -107,6 +107,7 @@ import org.springframework.web.util.WebUtils;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @since 3.1
|
||||
* @see HandlerMethodArgumentResolver
|
||||
* @see HandlerMethodReturnValueHandler
|
||||
@@ -612,16 +613,18 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
|
||||
logger.info("Detected @InitBinder methods in " + adviceBean);
|
||||
}
|
||||
}
|
||||
if (RequestBodyAdvice.class.isAssignableFrom(beanType)) {
|
||||
|
||||
boolean isRequestBodyAdvice = RequestBodyAdvice.class.isAssignableFrom(beanType);
|
||||
boolean isResponseBodyAdvice = ResponseBodyAdvice.class.isAssignableFrom(beanType);
|
||||
if (isRequestBodyAdvice || isResponseBodyAdvice) {
|
||||
requestResponseBodyAdviceBeans.add(adviceBean);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Detected RequestBodyAdvice bean in " + adviceBean);
|
||||
}
|
||||
}
|
||||
if (ResponseBodyAdvice.class.isAssignableFrom(beanType)) {
|
||||
requestResponseBodyAdviceBeans.add(adviceBean);
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Detected ResponseBodyAdvice bean in " + adviceBean);
|
||||
if (isRequestBodyAdvice) {
|
||||
logger.info("Detected RequestBodyAdvice bean in " + adviceBean);
|
||||
}
|
||||
else {
|
||||
logger.info("Detected ResponseBodyAdvice bean in " + adviceBean);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user