Polish "Add auto-configuration for JdkClientHttpConnector"

See gh-31709
pull/31828/head
Andy Wilkinson 2 years ago
parent e16734f937
commit 2814175505

@ -41,7 +41,7 @@ import org.springframework.web.reactive.function.client.WebClient;
@AutoConfiguration
@ConditionalOnClass(WebClient.class)
@Import({ ClientHttpConnectorConfiguration.ReactorNetty.class, ClientHttpConnectorConfiguration.JettyClient.class,
ClientHttpConnectorConfiguration.HttpClient5.class, ClientHttpConnectorConfiguration.JdkClient.class})
ClientHttpConnectorConfiguration.HttpClient5.class, ClientHttpConnectorConfiguration.JdkClient.class })
public class ClientHttpConnectorAutoConfiguration {
@Bean

@ -31,8 +31,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.client.reactive.ClientHttpConnector;
import org.springframework.http.client.reactive.HttpComponentsClientHttpConnector;
import org.springframework.http.client.reactive.JettyClientHttpConnector;
import org.springframework.http.client.reactive.JdkClientHttpConnector;
import org.springframework.http.client.reactive.JettyClientHttpConnector;
import org.springframework.http.client.reactive.JettyResourceFactory;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.http.client.reactive.ReactorResourceFactory;
@ -109,14 +109,16 @@ class ClientHttpConnectorConfiguration {
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(JdkClientHttpConnector.class)
@ConditionalOnClass(java.net.http.HttpClient.class)
@ConditionalOnMissingBean(ClientHttpConnector.class)
static class JdkClient {
@Bean
@Lazy
JdkClientHttpConnector jdkClientHttpConnector() {
return new JdkClientHttpConnector();
}
}
}

@ -87,8 +87,10 @@ class ClientHttpConnectorAutoConfigurationTests {
}
@Test
void whenReactorAndJettyAndHttpClientBeansAreUnavailableThenJdkClientAreDefined() {
this.contextRunner.withClassLoader(new FilteredClassLoader(HttpClient.class, ReactiveRequest.class, HttpAsyncClients.class))
void whenReactorJettyAndHttpClientBeansAreUnavailableThenJdkClientBeansAreDefined() {
this.contextRunner
.withClassLoader(
new FilteredClassLoader(HttpClient.class, ReactiveRequest.class, HttpAsyncClients.class))
.run((context) -> {
BeanDefinition customizerDefinition = context.getBeanFactory()
.getBeanDefinition("clientConnectorCustomizer");

@ -63,7 +63,7 @@ include::code:MyService[]
[[io.rest-client.webclient.runtime]]
==== WebClient Runtime
Spring Boot will auto-detect which `ClientHttpConnector` to use to drive `WebClient`, depending on the libraries available on the application classpath.
For now, Reactor Netty, Jetty RS client and Apache HttpClient are supported.
For now, Reactor Netty, Jetty RS client, Apache HttpClient, and the JDK's HttpClient are supported.
The `spring-boot-starter-webflux` starter depends on `io.projectreactor.netty:reactor-netty` by default, which brings both server and client implementations.
If you choose to use Jetty as a reactive server instead, you should add a dependency on the Jetty Reactive HTTP client library, `org.eclipse.jetty:jetty-reactive-httpclient`.

Loading…
Cancel
Save