From 1244fe4b4ae896310324b74ed2d40dc4ef775215 Mon Sep 17 00:00:00 2001 From: bsmahi Date: Sat, 29 Nov 2025 15:31:39 +0530 Subject: [PATCH] Upgraded to Spring Boot 4.0.0, Spring Cloud 2025.1.0, and Java 25 --- 04.docker/01-step-by-step-changes/readme.md | 53 +++++++++++++++---- 04.docker/api-gateway/pom.xml | 20 +++---- 04.docker/currency-conversion-service/pom.xml | 30 +++++------ .../CurrencyConversionController.java | 53 +++++++++++++------ 04.docker/currency-exchange-service/pom.xml | 30 +++++------ 04.docker/naming-server/pom.xml | 13 ++--- 6 files changed, 118 insertions(+), 81 deletions(-) diff --git a/04.docker/01-step-by-step-changes/readme.md b/04.docker/01-step-by-step-changes/readme.md index 2905a2e..7220602 100644 --- a/04.docker/01-step-by-step-changes/readme.md +++ b/04.docker/01-step-by-step-changes/readme.md @@ -199,21 +199,50 @@ Have a little bit of patience. Wait for 5-10 minutes if you do not see traces! ### Additional Changes For Spring Boot 3+ pom.xml +```xml + + + io.github.openfeign + feign-micrometer + ``` - - - io.github.openfeign - feign-micrometer - +> Starting with **Spring Boot 4**, the recommended way to call external APIs is to use **RestClient**, as **RestTemplate** is planned for deprecation. + +Reference Link: https://spring.io/blog/2025/09/30/the-state-of-http-clients-in-spring#the-future-of-http-clients-in-spring + +To use **RestClient**, you need to add the **HTTP Client** starter in `start.spring.io`. + +Follow these steps: + +1. Open **start.spring.io** +2. Click **Add Dependencies** +3. Type `client` in the search box +4. Select **HTTP Client** from the list + +```xml + + org.springframework.boot + spring-boot-starter-restclient + ``` CurrencyConversionController.java ``` +// Enable for Spring Boot 3.0.x +//@Configuration(proxyBeanMethods = false) +//class RestTemplateConfiguration { +// +// @Bean +// RestTemplate restTemplate(RestTemplateBuilder builder) { +// return builder.build(); +// } +//} + @Configuration(proxyBeanMethods = false) -class RestTemplateConfiguration { - +class RestClientConfiguration { + @Bean - RestTemplate restTemplate(RestTemplateBuilder builder) { + RestClient restClient(RestClient.Builder builder) { return builder.build(); } } @@ -224,8 +253,12 @@ public class CurrencyConversionController { @Autowired private CurrencyExchangeProxy proxy; - @Autowired - private RestTemplate restTemplate; + // Uncomment for Spring Boot 3.0.x +// @Autowired +// private RestTemplate restTemplate; + + @Autowired + private RestClient restClient; ``` diff --git a/04.docker/api-gateway/pom.xml b/04.docker/api-gateway/pom.xml index 246f061..8bdf4c7 100644 --- a/04.docker/api-gateway/pom.xml +++ b/04.docker/api-gateway/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.5.0 + 4.0.0 com.in28minutes.microservices @@ -15,8 +15,8 @@ Demo project for Spring Boot - 21 - 2025.0.0 + 25 + 2025.1.0 @@ -75,13 +75,17 @@ opentelemetry-exporter-zipkin - org.springframework.boot spring-boot-devtools runtime true + + org.springframework.boot + spring-boot-starter-actuator-test + test + org.springframework.boot spring-boot-starter-test @@ -116,12 +120,4 @@ - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - - diff --git a/04.docker/currency-conversion-service/pom.xml b/04.docker/currency-conversion-service/pom.xml index 6a9da91..24bdac2 100644 --- a/04.docker/currency-conversion-service/pom.xml +++ b/04.docker/currency-conversion-service/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.5.0 + 4.0.0 com.in28minutes.microservices @@ -15,8 +15,8 @@ Demo project for Spring Boot - 21 - 2025.0.0 + 25 + 2025.1.0 @@ -26,7 +26,7 @@ org.springframework.boot - spring-boot-starter-web + spring-boot-starter-webmvc com.in28minutes.microservices @@ -15,8 +15,8 @@ Demo project for Spring Boot - 21 - 2025.0.0 + 25 + 2025.1.0 @@ -27,7 +27,7 @@ org.springframework.boot - spring-boot-starter-web + spring-boot-starter-webmvc org.springframework.boot @@ -102,11 +102,16 @@ runtime true - - org.springframework.boot - spring-boot-starter-test - test - + + org.springframework.boot + spring-boot-starter-actuator-test + test + + + org.springframework.boot + spring-boot-starter-webmvc-test + test + @@ -136,12 +141,5 @@ - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - diff --git a/04.docker/naming-server/pom.xml b/04.docker/naming-server/pom.xml index 5019173..6fa4571 100644 --- a/04.docker/naming-server/pom.xml +++ b/04.docker/naming-server/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.5.0 + 4.0.0 com.in28minutes.microservices @@ -15,8 +15,8 @@ Demo project for Spring Boot - 21 - 2025.0.0 + 25 + 2025.1.0 @@ -75,12 +75,5 @@ - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - -