From 622e1e00442c1feb52b2aa039d01b560fc11061a Mon Sep 17 00:00:00 2001 From: Jay Choi Date: Fri, 27 Feb 2026 13:26:16 +0900 Subject: [PATCH 1/2] Fix @AutoConfigureWebTestClient preventing timeout property binding See gh-49340 Signed-off-by: Jay Choi --- .../reactive/AutoConfigureWebTestClient.java | 3 ++ ...TimeoutSpringBootTestIntegrationTests.java | 52 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebTestClientTimeoutSpringBootTestIntegrationTests.java diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/AutoConfigureWebTestClient.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/AutoConfigureWebTestClient.java index d3884b831db..1ea56bb1a7d 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/AutoConfigureWebTestClient.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/AutoConfigureWebTestClient.java @@ -26,6 +26,7 @@ import java.time.Duration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.test.autoconfigure.properties.PropertyMapping; +import org.springframework.boot.test.autoconfigure.properties.SkipPropertyMapping; import org.springframework.context.ApplicationContext; import org.springframework.test.web.reactive.server.WebTestClient; @@ -35,6 +36,7 @@ import org.springframework.test.web.reactive.server.WebTestClient; * mock requests and responses. At the moment, only WebFlux applications are supported. * * @author Stephane Nicoll + * @author Jay Choi * @since 2.0.0 * @see WebTestClientAutoConfiguration * @see WebTestClient#bindToApplicationContext(ApplicationContext) @@ -52,6 +54,7 @@ public @interface AutoConfigureWebTestClient { * {@link Duration#parse(CharSequence)}). * @return the web client timeout */ + @PropertyMapping(skip = SkipPropertyMapping.ON_DEFAULT_VALUE) String timeout() default ""; } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebTestClientTimeoutSpringBootTestIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebTestClientTimeoutSpringBootTestIntegrationTests.java new file mode 100644 index 00000000000..e69dbeb3191 --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebTestClientTimeoutSpringBootTestIntegrationTests.java @@ -0,0 +1,52 @@ +/* + * Copyright 2026-present 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.test.autoconfigure.web.reactive.webclient; + +import java.time.Duration; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.reactive.server.WebTestClient; +import org.springframework.web.reactive.config.EnableWebFlux; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SpringBootTest @SpringBootTest} with + * {@link AutoConfigureWebTestClient @AutoConfigureWebTestClient} timeout property + * binding. + * + * @author Jay Choi + */ +@SpringBootTest(properties = { "spring.main.web-application-type=reactive", "spring.test.webtestclient.timeout=30s" }, + classes = ExampleWebFluxApplication.class) +@AutoConfigureWebTestClient +@EnableWebFlux +class WebTestClientTimeoutSpringBootTestIntegrationTests { + + @Autowired + private WebTestClient webClient; + + @Test + void timeoutFromPropertyShouldBeApplied() { + assertThat(this.webClient).hasFieldOrPropertyWithValue("responseTimeout", Duration.ofSeconds(30)); + } + +} From a1b382a66b8b54f087f9c6e56591b401ee226646 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 27 Feb 2026 09:48:59 +0000 Subject: [PATCH 2/2] Polish "Fix @AutoConfigureWebTestClient preventing timeout property binding" See gh-49340 --- ...TimeoutSpringBootTestIntegrationTests.java | 56 +++++++++++++++---- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebTestClientTimeoutSpringBootTestIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebTestClientTimeoutSpringBootTestIntegrationTests.java index e69dbeb3191..8a5bf94be96 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebTestClientTimeoutSpringBootTestIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebTestClientTimeoutSpringBootTestIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2026-present the original author or authors. + * Copyright 2012-present 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. @@ -18,13 +18,14 @@ package org.springframework.boot.test.autoconfigure.web.reactive.webclient; import java.time.Duration; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.web.reactive.server.WebTestClient; -import org.springframework.web.reactive.config.EnableWebFlux; import static org.assertj.core.api.Assertions.assertThat; @@ -34,19 +35,52 @@ import static org.assertj.core.api.Assertions.assertThat; * binding. * * @author Jay Choi + * @author Andy Wilkinson */ -@SpringBootTest(properties = { "spring.main.web-application-type=reactive", "spring.test.webtestclient.timeout=30s" }, - classes = ExampleWebFluxApplication.class) -@AutoConfigureWebTestClient -@EnableWebFlux +@SpringBootTest(properties = { "spring.main.web-application-type=reactive" }, classes = ExampleWebFluxApplication.class) class WebTestClientTimeoutSpringBootTestIntegrationTests { - @Autowired - private WebTestClient webClient; + @Nested + @AutoConfigureWebTestClient + @TestPropertySource(properties = "spring.test.webtestclient.timeout=30s") + class TimeoutFromProperty { + + @Autowired + private WebTestClient webClient; + + @Test + void timeoutIsApplied() { + assertThat(this.webClient).hasFieldOrPropertyWithValue("responseTimeout", Duration.ofSeconds(30)); + } + + } + + @Nested + @AutoConfigureWebTestClient(timeout = "25s") + class TimeoutFromAnnotation { + + @Autowired + private WebTestClient webClient; + + @Test + void timeoutIsApplied() { + assertThat(this.webClient).hasFieldOrPropertyWithValue("responseTimeout", Duration.ofSeconds(25)); + } + + } + + @Nested + @AutoConfigureWebTestClient + class DefaultTimeout { + + @Autowired + private WebTestClient webClient; + + @Test + void timeoutIsApplied() { + assertThat(this.webClient).hasFieldOrPropertyWithValue("responseTimeout", Duration.ofSeconds(5)); + } - @Test - void timeoutFromPropertyShouldBeApplied() { - assertThat(this.webClient).hasFieldOrPropertyWithValue("responseTimeout", Duration.ofSeconds(30)); } }