Skip to content

Commit 93de5f4

Browse files
liquanchen9sbrannen
authored andcommitted
Avoid duplicate registration of [RequestBody|ResponseBody]Advice @ControllerAdvice
Prior to this commit, if a @ControllerAdvice implemented both RequestBodyAdvice and ResponseBodyAdvice, it was registered twice in RequestMappingHandlerAdapter. This commit ensures that such instances are only registered once. Closes gh-22638
1 parent f66362a commit 93de5f4

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -598,10 +598,7 @@ private void initControllerAdviceCache() {
598598
if (!binderMethods.isEmpty()) {
599599
this.initBinderAdviceCache.put(adviceBean, binderMethods);
600600
}
601-
if (RequestBodyAdvice.class.isAssignableFrom(beanType)) {
602-
requestResponseBodyAdviceBeans.add(adviceBean);
603-
}
604-
if (ResponseBodyAdvice.class.isAssignableFrom(beanType)) {
601+
if (RequestBodyAdvice.class.isAssignableFrom(beanType) || ResponseBodyAdvice.class.isAssignableFrom(beanType)) {
605602
requestResponseBodyAdviceBeans.add(adviceBean);
606603
}
607604
}

0 commit comments

Comments
 (0)