Skip to content

Commit 2336cdd

Browse files
committed
Relax conditions to create RestClient infrastructure
Previously, the necessary infrastructure to create a RestClient was only configured in a servlet-based application or in a reactive application if virtual threads are enabled. While this extra care was important in Spring Boot 4 as the aut-configuration is always available, this is no longer the case with Spring Boot 4. Indeed, an explicit module has to be added to the classpath now. This commit therefore relaxes the condition. If the module has been added, then the infrastructure is auto-configured. Closes gh-48308
1 parent 46f22b2 commit 2336cdd

File tree

3 files changed

+0
-96
lines changed

3 files changed

+0
-96
lines changed

module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/autoconfigure/NotReactiveWebApplicationOrVirtualThreadsExecutorEnabledCondition.java

Lines changed: 0 additions & 50 deletions
This file was deleted.

module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/autoconfigure/RestClientAutoConfiguration.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.springframework.boot.restclient.RestClientCustomizer;
3333
import org.springframework.boot.ssl.SslBundles;
3434
import org.springframework.context.annotation.Bean;
35-
import org.springframework.context.annotation.Conditional;
3635
import org.springframework.context.annotation.Configuration;
3736
import org.springframework.context.annotation.Scope;
3837
import org.springframework.core.Ordered;
@@ -57,7 +56,6 @@
5756
@AutoConfiguration(after = { ImperativeHttpClientAutoConfiguration.class, TaskExecutionAutoConfiguration.class,
5857
SslAutoConfiguration.class })
5958
@ConditionalOnClass(RestClient.class)
60-
@Conditional(NotReactiveWebApplicationOrVirtualThreadsExecutorEnabledCondition.class)
6159
public final class RestClientAutoConfiguration {
6260

6361
@Bean

module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/autoconfigure/RestClientAutoConfigurationTests.java

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@
2020
import java.util.List;
2121

2222
import org.junit.jupiter.api.Test;
23-
import org.junit.jupiter.api.condition.EnabledForJreRange;
24-
import org.junit.jupiter.api.condition.JRE;
2523
import org.mockito.InOrder;
2624

2725
import org.springframework.boot.autoconfigure.AutoConfigurations;
28-
import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration;
2926
import org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder;
3027
import org.springframework.boot.http.client.HttpClientSettings;
3128
import org.springframework.boot.http.client.HttpRedirects;
@@ -38,7 +35,6 @@
3835
import org.springframework.boot.ssl.SslBundle;
3936
import org.springframework.boot.ssl.SslBundles;
4037
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
41-
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
4238
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
4339
import org.springframework.context.annotation.Bean;
4440
import org.springframework.context.annotation.Configuration;
@@ -252,17 +248,6 @@ void shouldSupplyRestClientBuilderConfigurerWithAutoConfiguredHttpSettings() {
252248
});
253249
}
254250

255-
@Test
256-
void whenReactiveWebApplicationRestClientIsNotConfigured() {
257-
new ReactiveWebApplicationContextRunner()
258-
.withConfiguration(AutoConfigurations.of(RestClientAutoConfiguration.class))
259-
.run((context) -> {
260-
assertThat(context).doesNotHaveBean(HttpMessageConvertersRestClientCustomizer.class);
261-
assertThat(context).doesNotHaveBean(RestClientBuilderConfigurer.class);
262-
assertThat(context).doesNotHaveBean(RestClient.Builder.class);
263-
});
264-
}
265-
266251
@Test
267252
void whenServletWebApplicationRestClientIsConfigured() {
268253
new WebApplicationContextRunner().withConfiguration(AutoConfigurations.of(RestClientAutoConfiguration.class))
@@ -272,35 +257,6 @@ void whenServletWebApplicationRestClientIsConfigured() {
272257
});
273258
}
274259

275-
@Test
276-
@EnabledForJreRange(min = JRE.JAVA_21)
277-
void whenReactiveWebApplicationAndVirtualThreadsEnabledAndTaskExecutorBean() {
278-
new ReactiveWebApplicationContextRunner().withPropertyValues("spring.threads.virtual.enabled=true")
279-
.withConfiguration(
280-
AutoConfigurations.of(RestClientAutoConfiguration.class, TaskExecutionAutoConfiguration.class))
281-
.run((context) -> {
282-
assertThat(context).hasSingleBean(RestClientBuilderConfigurer.class);
283-
assertThat(context).hasSingleBean(RestClient.Builder.class);
284-
});
285-
}
286-
287-
@Test
288-
@EnabledForJreRange(min = JRE.JAVA_21)
289-
void whenReactiveWebApplicationAndVirtualThreadsDisabled() {
290-
new ReactiveWebApplicationContextRunner().withPropertyValues("spring.threads.virtual.enabled=false")
291-
.withConfiguration(
292-
AutoConfigurations.of(RestClientAutoConfiguration.class, TaskExecutionAutoConfiguration.class))
293-
.run((context) -> assertThat(context).doesNotHaveBean(RestClient.Builder.class));
294-
}
295-
296-
@Test
297-
@EnabledForJreRange(min = JRE.JAVA_21)
298-
void whenReactiveWebApplicationAndVirtualThreadsEnabledAndNoTaskExecutorBean() {
299-
new ReactiveWebApplicationContextRunner().withPropertyValues("spring.threads.virtual.enabled=true")
300-
.withConfiguration(AutoConfigurations.of(RestClientAutoConfiguration.class))
301-
.run((context) -> assertThat(context).doesNotHaveBean(RestClient.Builder.class));
302-
}
303-
304260
@Test
305261
void clientHttpMessageConverterCustomizersAreAppliedInOrder() {
306262
this.contextRunner.withUserConfiguration(ClientHttpMessageConverterCustomizersConfiguration.class)

0 commit comments

Comments
 (0)