Skip to content

Commit 93db1fa

Browse files
authored
Merge pull request #22 from bsmahi/main
Upgraded to Spring Boot 4.0.0, Spring Cloud 2025.1.0, and Java 25
2 parents c80ec17 + a978ab3 commit 93db1fa

File tree

22 files changed

+393
-597
lines changed

22 files changed

+393
-597
lines changed

02.restful-web-services/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.springframework.boot</groupId>
88
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>4.0.0-RC2</version>
9+
<version>4.0.0</version>
1010
<relativePath /> <!-- lookup parent from repository -->
1111
</parent>
1212
<groupId>com.in28minutes.rest.webservices</groupId>

03.microservices/01-step-by-step-changes/readme.md

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@
4343
<parent>
4444
<groupId>org.springframework.boot</groupId>
4545
<artifactId>spring-boot-starter-parent</artifactId>
46-
<version>2.7.3</version>
46+
<version>4.0.0</version>
4747
<relativePath/> <!-- lookup parent from repository -->
4848
</parent>
4949

5050
<properties>
51-
<java.version>21</java.version>
52-
<spring-cloud.version>2021.0.3</spring-cloud.version>
51+
<java.version>25</java.version>
52+
<spring-cloud.version>2025.1.0</spring-cloud.version>
5353
</properties>
5454
```
5555

@@ -750,9 +750,9 @@ package com.in28minutes.microservices.currencyexchangeservice;
750750

751751
import java.math.BigDecimal;
752752

753-
import javax.persistence.Column;
754-
import javax.persistence.Entity;
755-
import javax.persistence.Id;
753+
import jakarta.persistence.Column;
754+
import jakarta.persistence.Entity;
755+
import jakarta.persistence.Id;
756756

757757
@Entity
758758
public class CurrencyExchange {
@@ -1040,6 +1040,26 @@ public class CurrencyConversion {
10401040

10411041
Step 17 - Invoking Currency Exchange Microservice from Currency Conversion Microservice
10421042

1043+
> Starting with **Spring Boot 4**, the recommended way to call external APIs is to use **RestClient**, as **RestTemplate** is planned for deprecation.
1044+
1045+
Reference Link: https://spring.io/blog/2025/09/30/the-state-of-http-clients-in-spring#the-future-of-http-clients-in-spring
1046+
1047+
To use **RestClient**, you need to add the **HTTP Client** starter in `start.spring.io`.
1048+
1049+
Follow these steps:
1050+
1051+
1. Open **start.spring.io**
1052+
2. Click **Add Dependencies**
1053+
3. Type `client` in the search box
1054+
4. Select **HTTP Client** from the list
1055+
1056+
```xml
1057+
<dependency>
1058+
<groupId>org.springframework.boot</groupId>
1059+
<artifactId>spring-boot-starter-restclient</artifactId>
1060+
</dependency>
1061+
```
1062+
10431063
#### /currency-conversion-service/src/main/java/com/in28minutes/microservices/currencyconversionservice/CurrencyConversionController.java Modified
10441064

10451065
```java
@@ -1052,11 +1072,22 @@ import org.springframework.http.ResponseEntity;
10521072
import org.springframework.web.bind.annotation.GetMapping;
10531073
import org.springframework.web.bind.annotation.PathVariable;
10541074
import org.springframework.web.bind.annotation.RestController;
1055-
import org.springframework.web.client.RestTemplate;
1075+
// import org.springframework.web.client.RestTemplate;
1076+
1077+
@Configuration(proxyBeanMethods = false)
1078+
class RestClientConfiguration {
1079+
1080+
@Bean
1081+
RestClient restClient(RestClient.Builder builder) {
1082+
return builder.build();
1083+
}
1084+
}
10561085

10571086
@RestController
10581087
public class CurrencyConversionController {
1059-
1088+
1089+
@Autowired
1090+
private RestClient restClient;
10601091

10611092
@GetMapping("/currency-conversion/from/{from}/to/{to}/quantity/{quantity}")
10621093
public CurrencyConversion calculateCurrencyConversion(
@@ -1068,18 +1099,29 @@ public class CurrencyConversionController {
10681099
HashMap<String, String> uriVariables = new HashMap<>();
10691100
uriVariables.put("from",from);
10701101
uriVariables.put("to",to);
1102+
1103+
CurrencyConversion currencyConversion = restClient.get()
1104+
.uri("http://localhost:8000/currency-exchange/from/{from}/to/{to}", uriVariables)
1105+
.retrieve()
1106+
.body(CurrencyConversion.class);
1107+
1108+
return new CurrencyConversion(currencyConversion.getId(),
1109+
from, to, quantity,
1110+
currencyConversion.getConversionMultiple(),
1111+
quantity.multiply(currencyConversion.getConversionMultiple()),
1112+
currencyConversion.getEnvironment()+ " " + "rest client");
10711113

1072-
ResponseEntity<CurrencyConversion> responseEntity = new RestTemplate().getForEntity
1073-
("http://localhost:8000/currency-exchange/from/{from}/to/{to}",
1074-
CurrencyConversion.class, uriVariables);
1075-
1076-
CurrencyConversion currencyConversion = responseEntity.getBody();
1077-
1078-
return new CurrencyConversion(currencyConversion.getId(),
1079-
from, to, quantity,
1080-
currencyConversion.getConversionMultiple(),
1081-
quantity.multiply(currencyConversion.getConversionMultiple()),
1082-
currencyConversion.getEnvironment()+ " " + "rest template");
1114+
// ResponseEntity<CurrencyConversion> responseEntity = new RestTemplate().getForEntity
1115+
// ("http://localhost:8000/currency-exchange/from/{from}/to/{to}",
1116+
// CurrencyConversion.class, uriVariables);
1117+
//
1118+
// CurrencyConversion currencyConversion = responseEntity.getBody();
1119+
//
1120+
// return new CurrencyConversion(currencyConversion.getId(),
1121+
// from, to, quantity,
1122+
// currencyConversion.getConversionMultiple(),
1123+
// quantity.multiply(currencyConversion.getConversionMultiple()),
1124+
// currencyConversion.getEnvironment()+ " " + "rest template");
10831125

10841126
}
10851127

@@ -1684,10 +1726,15 @@ Changes for:
16841726

16851727
#### /currency-exchange-service/pom.xml Modified
16861728
New Lines
1729+
16871730
```xml
1731+
<properties>
1732+
<spring-aop.version>4.0.0-M2</spring-aop.version>
1733+
</properties>
16881734
<dependency>
16891735
<groupId>org.springframework.boot</groupId>
16901736
<artifactId>spring-boot-starter-aop</artifactId>
1737+
<version>${spring-aop.version}</version>
16911738
</dependency>
16921739

16931740
<dependency>

03.microservices/api-gateway/pom.xml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.5.0</version>
8+
<version>4.0.0</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
1111
<groupId>com.in28minutes.microservices</groupId>
@@ -15,8 +15,8 @@
1515
<description>Demo project for Spring Boot</description>
1616

1717
<properties>
18-
<java.version>21</java.version>
19-
<spring-cloud.version>2025.0.0</spring-cloud.version>
18+
<java.version>25</java.version>
19+
<spring-cloud.version>2025.1.0</spring-cloud.version>
2020
</properties>
2121

2222
<dependencies>
@@ -98,16 +98,20 @@
9898
<artifactId>opentelemetry-exporter-zipkin</artifactId>
9999
</dependency>
100100

101-
102101
<dependency>
103102
<groupId>org.springframework.boot</groupId>
104103
<artifactId>spring-boot-devtools</artifactId>
105104
<scope>runtime</scope>
106105
<optional>true</optional>
107106
</dependency>
107+
<dependency>
108+
<groupId>org.springframework.boot</groupId>
109+
<artifactId>spring-boot-starter-actuator-test</artifactId>
110+
<scope>test</scope>
111+
</dependency>
108112
<dependency>
109113
<groupId>org.springframework.boot</groupId>
110-
<artifactId>spring-boot-starter-test</artifactId>
114+
<artifactId>spring-boot-starter-webmvc-test</artifactId>
111115
<scope>test</scope>
112116
</dependency>
113117
</dependencies>
@@ -133,12 +137,4 @@
133137
</plugins>
134138
</build>
135139

136-
<repositories>
137-
<repository>
138-
<id>spring-milestones</id>
139-
<name>Spring Milestones</name>
140-
<url>https://repo.spring.io/milestone</url>
141-
</repository>
142-
</repositories>
143-
144140
</project>

03.microservices/currency-conversion-service/pom.xml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.5.0</version>
8+
<version>4.0.0</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
1111
<groupId>com.in28minutes.microservices</groupId>
@@ -15,8 +15,8 @@
1515
<description>Demo project for Spring Boot</description>
1616

1717
<properties>
18-
<java.version>21</java.version>
19-
<spring-cloud.version>2025.0.0</spring-cloud.version>
18+
<java.version>25</java.version>
19+
<spring-cloud.version>2025.1.0</spring-cloud.version>
2020
</properties>
2121

2222
<dependencies>
@@ -26,8 +26,13 @@
2626
</dependency>
2727
<dependency>
2828
<groupId>org.springframework.boot</groupId>
29-
<artifactId>spring-boot-starter-web</artifactId>
29+
<artifactId>spring-boot-starter-webmvc</artifactId>
3030
</dependency>
31+
<!-- RestTemplate Deprecated, please use restclient with the spring boot starter -->
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-restclient</artifactId>
35+
</dependency>
3136
<dependency>
3237
<groupId>org.springframework.cloud</groupId>
3338
<artifactId>spring-cloud-starter-config</artifactId>
@@ -112,9 +117,14 @@
112117
<scope>runtime</scope>
113118
<optional>true</optional>
114119
</dependency>
120+
<dependency>
121+
<groupId>org.springframework.boot</groupId>
122+
<artifactId>spring-boot-starter-actuator-test</artifactId>
123+
<scope>test</scope>
124+
</dependency>
115125
<dependency>
116126
<groupId>org.springframework.boot</groupId>
117-
<artifactId>spring-boot-starter-test</artifactId>
127+
<artifactId>spring-boot-starter-webmvc-test</artifactId>
118128
<scope>test</scope>
119129
</dependency>
120130
</dependencies>
@@ -139,13 +149,4 @@
139149
</plugin>
140150
</plugins>
141151
</build>
142-
143-
<repositories>
144-
<repository>
145-
<id>spring-milestones</id>
146-
<name>Spring Milestones</name>
147-
<url>https://repo.spring.io/milestone</url>
148-
</repository>
149-
</repositories>
150-
151152
</project>

03.microservices/currency-conversion-service/src/main/java/com/in28minutes/microservices/currencyconversionservice/CurrencyConversionController.java

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,31 @@
44
import java.util.HashMap;
55

66
import org.springframework.beans.factory.annotation.Autowired;
7-
import org.springframework.boot.web.client.RestTemplateBuilder;
7+
//import org.springframework.boot.web.client.RestTemplateBuilder;
88
import org.springframework.context.annotation.Bean;
99
import org.springframework.context.annotation.Configuration;
1010
import org.springframework.http.ResponseEntity;
1111
import org.springframework.web.bind.annotation.GetMapping;
1212
import org.springframework.web.bind.annotation.PathVariable;
1313
import org.springframework.web.bind.annotation.RestController;
14+
import org.springframework.web.client.RestClient;
1415
import org.springframework.web.client.RestTemplate;
1516

17+
// Enable for Spring Boot 3.0.x
18+
//@Configuration(proxyBeanMethods = false)
19+
//class RestTemplateConfiguration {
20+
//
21+
// @Bean
22+
// RestTemplate restTemplate(RestTemplateBuilder builder) {
23+
// return builder.build();
24+
// }
25+
//}
26+
1627
@Configuration(proxyBeanMethods = false)
17-
class RestTemplateConfiguration {
18-
28+
class RestClientConfiguration {
29+
1930
@Bean
20-
RestTemplate restTemplate(RestTemplateBuilder builder) {
31+
RestClient restClient(RestClient.Builder builder) {
2132
return builder.build();
2233
}
2334
}
@@ -27,9 +38,13 @@ public class CurrencyConversionController {
2738

2839
@Autowired
2940
private CurrencyExchangeProxy proxy;
30-
31-
@Autowired
32-
private RestTemplate restTemplate;
41+
42+
// Uncomment for Spring Boot 3.0.x
43+
// @Autowired
44+
// private RestTemplate restTemplate;
45+
46+
@Autowired
47+
private RestClient restClient;
3348

3449

3550
@GetMapping("/currency-conversion/from/{from}/to/{to}/quantity/{quantity}")
@@ -43,17 +58,22 @@ public CurrencyConversion calculateCurrencyConversion(
4358
uriVariables.put("from",from);
4459
uriVariables.put("to",to);
4560

46-
ResponseEntity<CurrencyConversion> responseEntity = restTemplate.getForEntity
47-
("http://localhost:8000/currency-exchange/from/{from}/to/{to}",
48-
CurrencyConversion.class, uriVariables);
61+
// ResponseEntity<CurrencyConversion> responseEntity = restTemplate.getForEntity
62+
// ("http://localhost:8000/currency-exchange/from/{from}/to/{to}",
63+
// CurrencyConversion.class, uriVariables);
64+
65+
CurrencyConversion currencyConversion = restClient.get()
66+
.uri("http://localhost:8000/currency-exchange/from/{from}/to/{to}", uriVariables)
67+
.retrieve()
68+
.body(CurrencyConversion.class);
4969

50-
CurrencyConversion currencyConversion = responseEntity.getBody();
70+
// CurrencyConversion currencyConversion = responseEntity.getBody();
5171

5272
return new CurrencyConversion(currencyConversion.getId(),
5373
from, to, quantity,
5474
currencyConversion.getConversionMultiple(),
5575
quantity.multiply(currencyConversion.getConversionMultiple()),
56-
currencyConversion.getEnvironment()+ " " + "rest template");
76+
currencyConversion.getEnvironment()+ " " + "rest client");
5777

5878
}
5979

0 commit comments

Comments
 (0)