From d855ea6861b8bf530518e8fff2bdc8c52ce8b81e Mon Sep 17 00:00:00 2001 From: Jay Choi Date: Fri, 27 Feb 2026 13:26:16 +0900 Subject: [PATCH] Fix @AutoConfigureWebTestClient preventing timeout property binding Closes gh-49331 Signed-off-by: Jay Choi --- .../AutoConfigureWebTestClient.java | 3 ++ ...TimeoutSpringBootTestIntegrationTests.java | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 module/spring-boot-webtestclient/src/test/java/org/springframework/boot/webtestclient/autoconfigure/WebTestClientTimeoutSpringBootTestIntegrationTests.java diff --git a/module/spring-boot-webtestclient/src/main/java/org/springframework/boot/webtestclient/autoconfigure/AutoConfigureWebTestClient.java b/module/spring-boot-webtestclient/src/main/java/org/springframework/boot/webtestclient/autoconfigure/AutoConfigureWebTestClient.java index eef6aa7467c8..1f05509822f1 100644 --- a/module/spring-boot-webtestclient/src/main/java/org/springframework/boot/webtestclient/autoconfigure/AutoConfigureWebTestClient.java +++ b/module/spring-boot-webtestclient/src/main/java/org/springframework/boot/webtestclient/autoconfigure/AutoConfigureWebTestClient.java @@ -26,12 +26,14 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.test.context.PropertyMapping; +import org.springframework.boot.test.context.PropertyMapping.Skip; import org.springframework.test.web.reactive.server.WebTestClient; /** * Annotation that can be applied to a test class to enable a {@link WebTestClient}. * * @author Stephane Nicoll + * @author Jay Choi * @since 4.0.0 * @see WebTestClientAutoConfiguration */ @@ -48,6 +50,7 @@ * {@link Duration#parse(CharSequence)}). * @return the web client timeout */ + @PropertyMapping(skip = Skip.ON_DEFAULT_VALUE) String timeout() default ""; } diff --git a/module/spring-boot-webtestclient/src/test/java/org/springframework/boot/webtestclient/autoconfigure/WebTestClientTimeoutSpringBootTestIntegrationTests.java b/module/spring-boot-webtestclient/src/test/java/org/springframework/boot/webtestclient/autoconfigure/WebTestClientTimeoutSpringBootTestIntegrationTests.java new file mode 100644 index 000000000000..03e0d9c74fe3 --- /dev/null +++ b/module/spring-boot-webtestclient/src/test/java/org/springframework/boot/webtestclient/autoconfigure/WebTestClientTimeoutSpringBootTestIntegrationTests.java @@ -0,0 +1,51 @@ +/* + * 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.webtestclient.autoconfigure; + +import java.time.Duration; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +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 = ExampleWebTestClientApplication.class) +@AutoConfigureWebTestClient +@EnableWebFlux +class WebTestClientTimeoutSpringBootTestIntegrationTests { + + @Autowired + private WebTestClient webClient; + + @Test + void timeoutFromPropertyShouldBeApplied() { + assertThat(this.webClient).hasFieldOrPropertyWithValue("responseTimeout", Duration.ofSeconds(30)); + } + +}