Skip to content

Commit a69d971

Browse files
committed
Merge branch '5.3.x'
2 parents 7700570 + 64c96c5 commit a69d971

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ErrorsMethodArgumentResolver.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -33,7 +33,8 @@
3333

3434
/**
3535
* Resolve {@link Errors} or {@link BindingResult} method arguments.
36-
* An {@code Errors} argument is expected to appear immediately after the
36+
*
37+
* <p>An {@code Errors} argument is expected to appear immediately after the
3738
* model attribute in the method signature.
3839
*
3940
* @author Rossen Stoyanchev
@@ -86,7 +87,7 @@ private Object getErrors(MethodParameter parameter, BindingContext context) {
8687
"Either declare the @ModelAttribute without an async wrapper type or " +
8788
"handle a WebExchangeBindException error signal through the async type.");
8889

89-
ModelAttribute ann = parameter.getParameterAnnotation(ModelAttribute.class);
90+
ModelAttribute ann = attributeParam.getParameterAnnotation(ModelAttribute.class);
9091
String name = (ann != null && StringUtils.hasText(ann.value()) ?
9192
ann.value() : Conventions.getVariableNameForParameter(attributeParam));
9293
Object errors = context.getModel().asMap().get(BindingResult.MODEL_KEY_PREFIX + name);

spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ErrorsMethodArgumentResolverTests.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -81,6 +81,20 @@ void resolve() {
8181
assertThat(actual).isSameAs(bindingResult);
8282
}
8383

84+
@Test
85+
void resolveOnBindingResultAndModelAttributeWithCustomName() {
86+
BindingResult bindingResult = createBindingResult(new Foo(), "custom");
87+
this.bindingContext.getModel().asMap().put(BindingResult.MODEL_KEY_PREFIX + "custom", bindingResult);
88+
89+
ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handleWithCustomModelAttributeName").build();
90+
91+
MethodParameter parameter = testMethod.arg(Errors.class);
92+
Object actual = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
93+
.block(Duration.ofMillis(5000));
94+
95+
assertThat(actual).isSameAs(bindingResult);
96+
}
97+
8498
private BindingResult createBindingResult(Foo target, String name) {
8599
DataBinder binder = this.bindingContext.createDataBinder(this.exchange, target, name);
86100
return binder.getBindingResult();
@@ -98,6 +112,20 @@ void resolveWithMono() {
98112
assertThat(actual).isSameAs(bindingResult);
99113
}
100114

115+
@Test
116+
void resolveWithMonoOnBindingResultAndModelAttributeWithCustomName() {
117+
BindingResult bindingResult = createBindingResult(new Foo(), "custom");
118+
this.bindingContext.getModel().asMap().put(BindingResult.MODEL_KEY_PREFIX + "custom", Mono.just(bindingResult));
119+
120+
ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handleWithCustomModelAttributeName").build();
121+
122+
MethodParameter parameter = testMethod.arg(Errors.class);
123+
Object actual = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
124+
.block(Duration.ofMillis(5000));
125+
126+
assertThat(actual).isSameAs(bindingResult);
127+
}
128+
101129
@Test
102130
void resolveWithMonoOnBindingResultAndModelAttribute() {
103131
MethodParameter parameter = this.testMethod.arg(BindingResult.class);
@@ -150,4 +178,14 @@ void handle(
150178
String string) {
151179
}
152180

181+
@SuppressWarnings("unused")
182+
void handleWithCustomModelAttributeName(
183+
@ModelAttribute("custom") Foo foo,
184+
Errors errors,
185+
@ModelAttribute Mono<Foo> fooMono,
186+
BindingResult bindingResult,
187+
Mono<Errors> errorsMono,
188+
String string) {
189+
}
190+
153191
}

0 commit comments

Comments
 (0)