Skip to content

Commit 51e9f6c

Browse files
authored
Made changes to upgrade the module spring-resttemplate-3 to Spring Boot 3. (#15455)
1 parent 288178f commit 51e9f6c

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

spring-web-modules/spring-resttemplate-3/pom.xml

+12-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
<parent>
1212
<groupId>com.baeldung</groupId>
13-
<artifactId>parent-boot-2</artifactId>
13+
<artifactId>parent-boot-3</artifactId>
1414
<version>0.0.1-SNAPSHOT</version>
15-
<relativePath>../../parent-boot-2</relativePath>
15+
<relativePath>../../parent-boot-3</relativePath>
1616
</parent>
1717

1818
<dependencies>
@@ -24,6 +24,16 @@
2424
<groupId>org.springframework.boot</groupId>
2525
<artifactId>spring-boot-starter-test</artifactId>
2626
</dependency>
27+
<dependency>
28+
<groupId>org.apache.httpcomponents.client5</groupId>
29+
<artifactId>httpclient5</artifactId>
30+
<version>${httpclient5.version}</version>
31+
</dependency>
2732
</dependencies>
2833

34+
<properties>
35+
<start-class>com.baeldung.resttemplate.methods.RestTemplateMethodsApplication</start-class>
36+
<httpclient5.version>5.2.1</httpclient5.version>
37+
</properties>
38+
2939
</project>

spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/custom/CustomRestTemplateConfiguration.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
import javax.net.ssl.SSLContext;
1111

12-
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
13-
import org.apache.http.impl.client.CloseableHttpClient;
14-
import org.apache.http.impl.client.HttpClients;
15-
import org.apache.http.ssl.SSLContextBuilder;
12+
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
13+
import org.apache.hc.client5.http.impl.classic.HttpClients;
14+
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
15+
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
16+
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
17+
import org.apache.hc.core5.ssl.SSLContextBuilder;
1618
import org.springframework.beans.factory.annotation.Value;
1719
import org.springframework.context.annotation.Bean;
1820
import org.springframework.context.annotation.Configuration;
@@ -38,7 +40,11 @@ public RestTemplate restTemplate() throws KeyManagementException, NoSuchAlgorith
3840
.loadTrustMaterial(trustStore.getURL(), trustStorePassword.toCharArray()).build();
3941
SSLConnectionSocketFactory sslConFactory = new SSLConnectionSocketFactory(sslContext);
4042

41-
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslConFactory).build();
43+
final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create()
44+
.setSSLSocketFactory(sslConFactory)
45+
.build();
46+
47+
CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm).build();
4248
ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
4349
return new RestTemplate(requestFactory);
4450
}

0 commit comments

Comments
 (0)