Skip to content

Commit ec4d52e

Browse files
committed
Add ReactiveResponseConsumer classpath check to http5 auto-configuration
Closes gh-34964
1 parent 947ac8d commit ec4d52e

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

spring-boot-project/spring-boot-autoconfigure/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ dependencies {
7373
exclude group: "commons-logging", module: "commons-logging"
7474
}
7575
optional("org.apache.httpcomponents.client5:httpclient5")
76+
optional("org.apache.httpcomponents.core5:httpcore5-reactive")
7677
optional("org.apache.kafka:kafka-streams")
7778
optional("org.apache.solr:solr-solrj") {
7879
exclude group: "org.slf4j", module: "jcl-over-slf4j"
@@ -275,4 +276,4 @@ tasks.named("checkSpringConfigurationMetadata").configure {
275276
"spring.datasource.tomcat.*",
276277
"spring.groovy.template.configuration.*"
277278
]
278-
}
279+
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
2020
import org.apache.hc.core5.http.nio.AsyncRequestProducer;
21+
import org.apache.hc.core5.reactive.ReactiveResponseConsumer;
2122
import org.eclipse.jetty.client.HttpClient;
2223
import org.eclipse.jetty.util.ssl.SslContextFactory;
2324

@@ -87,7 +88,7 @@ JettyClientHttpConnector jettyClientHttpConnector(JettyResourceFactory jettyReso
8788
}
8889

8990
@Configuration(proxyBeanMethods = false)
90-
@ConditionalOnClass({ HttpAsyncClients.class, AsyncRequestProducer.class })
91+
@ConditionalOnClass({ HttpAsyncClients.class, AsyncRequestProducer.class, ReactiveResponseConsumer.class })
9192
@ConditionalOnMissingBean(ClientHttpConnector.class)
9293
static class HttpClient5 {
9394

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorConfigurationTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
import org.junit.jupiter.api.Test;
2525

2626
import org.springframework.boot.autoconfigure.AutoConfigurations;
27+
import org.springframework.boot.test.context.FilteredClassLoader;
2728
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
2829
import org.springframework.context.annotation.Bean;
30+
import org.springframework.http.client.reactive.HttpComponentsClientHttpConnector;
2931
import org.springframework.http.client.reactive.JettyClientHttpConnector;
3032
import org.springframework.http.client.reactive.JettyResourceFactory;
3133
import org.springframework.test.util.ReflectionTestUtils;
@@ -38,6 +40,7 @@
3840
*
3941
* @author Phillip Webb
4042
* @author Brian Clozel
43+
* @author Moritz Halbritter
4144
*/
4245
class ClientHttpConnectorConfigurationTests {
4346

@@ -83,6 +86,14 @@ void shouldApplyHttpClientMapper() {
8386
});
8487
}
8588

89+
@Test
90+
void shouldNotConfigureReactiveHttpClient5WhenHttpCore5ReactiveJarIsMissing() {
91+
new ReactiveWebApplicationContextRunner()
92+
.withClassLoader(new FilteredClassLoader("org.apache.hc.core5.reactive"))
93+
.withConfiguration(AutoConfigurations.of(ClientHttpConnectorConfiguration.HttpClient5.class))
94+
.run((context) -> assertThat(context).doesNotHaveBean(HttpComponentsClientHttpConnector.class));
95+
}
96+
8697
static class CustomHttpClientMapper {
8798

8899
static boolean called = false;

0 commit comments

Comments
 (0)