|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2023 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -78,6 +78,8 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
78 | 78 | @Nullable
|
79 | 79 | private MethodValidator methodValidator;
|
80 | 80 |
|
| 81 | + private Class<?>[] validationGroups = EMPTY_GROUPS; |
| 82 | + |
81 | 83 |
|
82 | 84 | /**
|
83 | 85 | * Create an instance from a {@code HandlerMethod}.
|
@@ -149,6 +151,8 @@ public void setDataBinderFactory(WebDataBinderFactory dataBinderFactory) {
|
149 | 151 | */
|
150 | 152 | public void setMethodValidator(@Nullable MethodValidator methodValidator) {
|
151 | 153 | this.methodValidator = methodValidator;
|
| 154 | + this.validationGroups = (methodValidator != null ? |
| 155 | + methodValidator.determineValidationGroups(getBean(), getBridgedMethod()) : EMPTY_GROUPS); |
152 | 156 | }
|
153 | 157 |
|
154 | 158 |
|
@@ -180,17 +184,16 @@ public Object invokeForRequest(NativeWebRequest request, @Nullable ModelAndViewC
|
180 | 184 | logger.trace("Arguments: " + Arrays.toString(args));
|
181 | 185 | }
|
182 | 186 |
|
183 |
| - Class<?>[] groups = getValidationGroups(); |
184 | 187 | if (shouldValidateArguments() && this.methodValidator != null) {
|
185 | 188 | this.methodValidator.applyArgumentValidation(
|
186 |
| - getBean(), getBridgedMethod(), getMethodParameters(), args, groups); |
| 189 | + getBean(), getBridgedMethod(), getMethodParameters(), args, this.validationGroups); |
187 | 190 | }
|
188 | 191 |
|
189 | 192 | Object returnValue = doInvoke(args);
|
190 | 193 |
|
191 | 194 | if (shouldValidateReturnValue() && this.methodValidator != null) {
|
192 | 195 | this.methodValidator.applyReturnValueValidation(
|
193 |
| - getBean(), getBridgedMethod(), getReturnType(), returnValue, groups); |
| 196 | + getBean(), getBridgedMethod(), getReturnType(), returnValue, this.validationGroups); |
194 | 197 | }
|
195 | 198 |
|
196 | 199 | return returnValue;
|
@@ -238,11 +241,6 @@ protected Object[] getMethodArgumentValues(NativeWebRequest request, @Nullable M
|
238 | 241 | return args;
|
239 | 242 | }
|
240 | 243 |
|
241 |
| - private Class<?>[] getValidationGroups() { |
242 |
| - return ((shouldValidateArguments() || shouldValidateReturnValue()) && this.methodValidator != null ? |
243 |
| - this.methodValidator.determineValidationGroups(getBean(), getBridgedMethod()) : EMPTY_GROUPS); |
244 |
| - } |
245 |
| - |
246 | 244 | /**
|
247 | 245 | * Invoke the handler method with the given argument values.
|
248 | 246 | */
|
|
0 commit comments