Skip to content

Commit a8c5885

Browse files
quaffrstoyanchev
authored andcommitted
Fix wrong document about RequestHeaderArgumentResolver
Also test is added to verify that. Signed-off-by: Yanming Zhou <[email protected]> See gh-34230
1 parent 7d84427 commit a8c5885

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

framework-docs/modules/ROOT/pages/integration/rest-clients.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ method parameters:
940940
| `@RequestHeader`
941941
| Add a request header or multiple headers. The argument may be a `Map<String, ?>` or
942942
`MultiValueMap<String, ?>` with multiple headers, a `Collection<?>` of values, or an
943-
individual value. Type conversion is supported for non-String values. This overrides
943+
individual value. Type conversion is supported for non-String values. This does not override
944944
the annotation's `headers` attribute.
945945

946946
| `@PathVariable`

spring-web/src/test/java/org/springframework/web/service/invoker/RequestHeaderArgumentResolverTests.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -23,6 +23,7 @@
2323
import org.springframework.util.ObjectUtils;
2424
import org.springframework.web.bind.annotation.RequestHeader;
2525
import org.springframework.web.service.annotation.GetExchange;
26+
import org.springframework.web.service.annotation.HttpExchange;
2627

2728
import static org.assertj.core.api.Assertions.assertThat;
2829

@@ -32,6 +33,7 @@
3233
*
3334
* @author Olga Maciaszek-Sharma
3435
* @author Rossen Stoyanchev
36+
* @author Yanming Zhou
3537
*/
3638
class RequestHeaderArgumentResolverTests {
3739

@@ -49,6 +51,12 @@ void header() {
4951
assertRequestHeaders("id", "test");
5052
}
5153

54+
@Test
55+
void doesNotOverrideAnnotationHeaders() {
56+
this.service.executeWithAnnotationHeaders("test");
57+
assertRequestHeaders("id", "default", "test");
58+
}
59+
5260
private void assertRequestHeaders(String key, String... values) {
5361
List<String> actualValues = this.client.getRequestValues().getHeaders().get(key);
5462
if (ObjectUtils.isEmpty(values)) {
@@ -65,6 +73,9 @@ private interface Service {
6573
@GetExchange
6674
void execute(@RequestHeader String id);
6775

76+
@HttpExchange(method = "GET", headers = "id=default")
77+
void executeWithAnnotationHeaders(@RequestHeader String id);
78+
6879
}
6980

7081
}

0 commit comments

Comments
 (0)