Polish 'Auto-configure rest client when virtual threads are enabled'
See gh-44952
This commit is contained in:
@@ -17,8 +17,10 @@
|
||||
package org.springframework.boot.autoconfigure.web.client;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnThreading;
|
||||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
||||
import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.thread.Threading;
|
||||
import org.springframework.context.annotation.Conditional;
|
||||
|
||||
@@ -28,10 +30,10 @@ import org.springframework.context.annotation.Conditional;
|
||||
*
|
||||
* @author Dmitry Sulman
|
||||
*/
|
||||
class NotReactiveWebApplicationOrVirtualThreadsEnabledCondition extends AnyNestedCondition {
|
||||
class NotReactiveWebApplicationOrVirtualThreadsExecutorEnabledCondition extends AnyNestedCondition {
|
||||
|
||||
NotReactiveWebApplicationOrVirtualThreadsEnabledCondition() {
|
||||
super(ConfigurationPhase.PARSE_CONFIGURATION);
|
||||
NotReactiveWebApplicationOrVirtualThreadsExecutorEnabledCondition() {
|
||||
super(ConfigurationPhase.REGISTER_BEAN);
|
||||
}
|
||||
|
||||
@Conditional(NotReactiveWebApplicationCondition.class)
|
||||
@@ -40,6 +42,7 @@ class NotReactiveWebApplicationOrVirtualThreadsEnabledCondition extends AnyNeste
|
||||
}
|
||||
|
||||
@ConditionalOnThreading(Threading.VIRTUAL)
|
||||
@ConditionalOnBean(name = TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME)
|
||||
private static final class VirtualThreadsEnabled {
|
||||
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.http.client.HttpClientAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration;
|
||||
import org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder;
|
||||
import org.springframework.boot.http.client.ClientHttpRequestFactorySettings;
|
||||
import org.springframework.boot.ssl.SslBundles;
|
||||
@@ -51,9 +52,9 @@ import org.springframework.web.client.RestClient.Builder;
|
||||
* @since 3.2.0
|
||||
*/
|
||||
@AutoConfiguration(after = { HttpClientAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,
|
||||
SslAutoConfiguration.class })
|
||||
SslAutoConfiguration.class, TaskExecutionAutoConfiguration.class })
|
||||
@ConditionalOnClass(RestClient.class)
|
||||
@Conditional(NotReactiveWebApplicationOrVirtualThreadsEnabledCondition.class)
|
||||
@Conditional(NotReactiveWebApplicationOrVirtualThreadsExecutorEnabledCondition.class)
|
||||
public class RestClientAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.http.client.HttpClientAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration;
|
||||
import org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder;
|
||||
import org.springframework.boot.http.client.ClientHttpRequestFactorySettings;
|
||||
import org.springframework.boot.http.client.ClientHttpRequestFactorySettings.Redirects;
|
||||
@@ -57,6 +58,7 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Arjen Poutsma
|
||||
* @author Moritz Halbritter
|
||||
* @author Dmytro Nosan
|
||||
* @author Dmitry Sulman
|
||||
*/
|
||||
class RestClientAutoConfigurationTests {
|
||||
|
||||
@@ -287,9 +289,10 @@ class RestClientAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
@EnabledForJreRange(min = JRE.JAVA_21)
|
||||
void whenReactiveWebApplicationAndVirtualThreadsAreEnabledOnJava21AndLaterRestClientIsConfigured() {
|
||||
void whenReactiveWebApplicationAndVirtualThreadsEnabledAndTaskExecutorBean() {
|
||||
new ReactiveWebApplicationContextRunner().withPropertyValues("spring.threads.virtual.enabled=true")
|
||||
.withConfiguration(AutoConfigurations.of(RestClientAutoConfiguration.class))
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(RestClientAutoConfiguration.class, TaskExecutionAutoConfiguration.class))
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(HttpMessageConvertersRestClientCustomizer.class);
|
||||
assertThat(context).hasSingleBean(RestClientBuilderConfigurer.class);
|
||||
@@ -297,6 +300,23 @@ class RestClientAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledForJreRange(min = JRE.JAVA_21)
|
||||
void whenReactiveWebApplicationAndVirtualThreadsDisabled() {
|
||||
new ReactiveWebApplicationContextRunner().withPropertyValues("spring.threads.virtual.enabled=false")
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(RestClientAutoConfiguration.class, TaskExecutionAutoConfiguration.class))
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(RestClient.Builder.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledForJreRange(min = JRE.JAVA_21)
|
||||
void whenReactiveWebApplicationAndVirtualThreadsEnabledAndNoTaskExecutorBean() {
|
||||
new ReactiveWebApplicationContextRunner().withPropertyValues("spring.threads.virtual.enabled=true")
|
||||
.withConfiguration(AutoConfigurations.of(RestClientAutoConfiguration.class))
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(RestClient.Builder.class));
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class CodecConfiguration {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user