Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache validationGroups for subsequent requests #32078

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -56,6 +56,7 @@
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @author Sebastien Deleuze
* @author Yanming Zhou
* @since 3.1
*/
public class InvocableHandlerMethod extends HandlerMethod {
Expand All @@ -78,6 +79,9 @@ public class InvocableHandlerMethod extends HandlerMethod {
@Nullable
private MethodValidator methodValidator;

@Nullable
private Class<?>[] validationGroups;


/**
* Create an instance from a {@code HandlerMethod}.
Expand Down Expand Up @@ -180,7 +184,10 @@ public Object invokeForRequest(NativeWebRequest request, @Nullable ModelAndViewC
logger.trace("Arguments: " + Arrays.toString(args));
}

Class<?>[] groups = getValidationGroups();
Class<?>[] groups = this.validationGroups;
if (groups == null) {
groups = this.validationGroups = getValidationGroups();
}
if (shouldValidateArguments() && this.methodValidator != null) {
this.methodValidator.applyArgumentValidation(
getBean(), getBridgedMethod(), getMethodParameters(), args, groups);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand Down Expand Up @@ -64,6 +64,7 @@
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @author Sebastien Deleuze
* @author Yanming Zhou
* @since 5.0
*/
public class InvocableHandlerMethod extends HandlerMethod {
Expand All @@ -87,6 +88,9 @@ public class InvocableHandlerMethod extends HandlerMethod {
@Nullable
private MethodValidator methodValidator;

@Nullable
private Class<?>[] validationGroups;


/**
* Create an instance from a {@code HandlerMethod}.
Expand Down Expand Up @@ -166,7 +170,10 @@ public Mono<HandlerResult> invoke(
ServerWebExchange exchange, BindingContext bindingContext, Object... providedArgs) {

return getMethodArgumentValues(exchange, bindingContext, providedArgs).flatMap(args -> {
Class<?>[] groups = getValidationGroups();
Class<?>[] groups = this.validationGroups;
if (groups == null) {
groups = this.validationGroups = getValidationGroups();
}
if (shouldValidateArguments() && this.methodValidator != null) {
this.methodValidator.applyArgumentValidation(
getBean(), getBridgedMethod(), getMethodParameters(), args, groups);
Expand Down