From 93de5f407e394b70b9a3fa89e35340008d340cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=A8=E5=9F=8E?= Date: Fri, 22 Mar 2019 14:51:29 +0800 Subject: [PATCH] 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 --- .../method/annotation/RequestMappingHandlerAdapter.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java index 02f6afac8a..a89a584cea 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java @@ -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. @@ -598,10 +598,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter if (!binderMethods.isEmpty()) { this.initBinderAdviceCache.put(adviceBean, binderMethods); } - if (RequestBodyAdvice.class.isAssignableFrom(beanType)) { - requestResponseBodyAdviceBeans.add(adviceBean); - } - if (ResponseBodyAdvice.class.isAssignableFrom(beanType)) { + if (RequestBodyAdvice.class.isAssignableFrom(beanType) || ResponseBodyAdvice.class.isAssignableFrom(beanType)) { requestResponseBodyAdviceBeans.add(adviceBean); } } -- GitLab