Skip to content

Commit c84204b

Browse files
committed
Remove Netty4 auto-configuration in RestTemplate
This commit removes the automatic configuration of the Netty request factory in RestTemplateBuilder, for the following reasons: * as of Spring 5, `Netty4ClientHttpRequestFactory` is now deprecated * there are quite a few issues logged in Spring Framework (duplicate headers, such as SPR-15446 and SPR-15476) * by default, the `Netty4ClientHttpRequestFactory` is adding a "Connection: close" request header to all outgoing requests, which means that the underlying HTTP connection won't be reused between requests (which is a performance problem) In that case, using any other request factory is a better choice for Spring Boot 2.0+. Note that the `RestTemplateBuilder` still allows to provide it manually with the request factory to use. Developers can still choose this option and will be aware of its deprecation status. Fixes gh-9150
1 parent 4a47c1e commit c84204b

File tree

3 files changed

+0
-26
lines changed

3 files changed

+0
-26
lines changed

spring-boot/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,6 @@
321321
<artifactId>mariadb-java-client</artifactId>
322322
<scope>test</scope>
323323
</dependency>
324-
<dependency>
325-
<groupId>io.netty</groupId>
326-
<artifactId>netty-all</artifactId>
327-
<scope>test</scope>
328-
</dependency>
329324
<dependency>
330325
<groupId>org.postgresql</groupId>
331326
<artifactId>postgresql</artifactId>

spring-boot/src/main/java/org/springframework/boot/web/client/RestTemplateBuilder.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ public class RestTemplateBuilder {
7272
"org.springframework.http.client.OkHttp3ClientHttpRequestFactory");
7373
candidates.put("com.squareup.okhttp.OkHttpClient",
7474
"org.springframework.http.client.OkHttpClientHttpRequestFactory");
75-
candidates.put("io.netty.channel.EventLoopGroup",
76-
"org.springframework.http.client.Netty4ClientHttpRequestFactory");
7775
REQUEST_FACTORY_CANDIDATES = Collections.unmodifiableMap(candidates);
7876
}
7977

spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.springframework.http.client.ClientHttpRequestFactory;
3232
import org.springframework.http.client.ClientHttpRequestInterceptor;
3333
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
34-
import org.springframework.http.client.Netty4ClientHttpRequestFactory;
3534
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
3635
import org.springframework.http.client.SimpleClientHttpRequestFactory;
3736
import org.springframework.http.client.support.BasicAuthorizationInterceptor;
@@ -465,24 +464,6 @@ public void readTimeoutCanBeConfiguredOnSimpleRequestFactory() {
465464
.isEqualTo(1234);
466465
}
467466

468-
@Test
469-
public void connectTimeoutCanBeConfiguredOnNetty4RequestFactory() {
470-
ClientHttpRequestFactory requestFactory = this.builder
471-
.requestFactory(Netty4ClientHttpRequestFactory.class)
472-
.setConnectTimeout(1234).build().getRequestFactory();
473-
assertThat(ReflectionTestUtils.getField(requestFactory, "connectTimeout"))
474-
.isEqualTo(1234);
475-
}
476-
477-
@Test
478-
public void readTimeoutCanBeConfiguredOnNetty4RequestFactory() {
479-
ClientHttpRequestFactory requestFactory = this.builder
480-
.requestFactory(Netty4ClientHttpRequestFactory.class).setReadTimeout(1234)
481-
.build().getRequestFactory();
482-
assertThat(ReflectionTestUtils.getField(requestFactory, "readTimeout"))
483-
.isEqualTo(1234);
484-
}
485-
486467
@Test
487468
public void connectTimeoutCanBeConfiguredOnOkHttp3RequestFactory() {
488469
ClientHttpRequestFactory requestFactory = this.builder

0 commit comments

Comments
 (0)