Skip to content

Commit 1244fe4

Browse files
committed
Upgraded to Spring Boot 4.0.0, Spring Cloud 2025.1.0, and Java 25
1 parent 93db1fa commit 1244fe4

File tree

6 files changed

+118
-81
lines changed

6 files changed

+118
-81
lines changed

04.docker/01-step-by-step-changes/readme.md

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,21 +199,50 @@ Have a little bit of patience. Wait for 5-10 minutes if you do not see traces!
199199
### Additional Changes For Spring Boot 3+
200200

201201
pom.xml
202+
```xml
203+
<!-- Enables tracing of REST API calls made using Feign-->
204+
<dependency>
205+
<groupId>io.github.openfeign</groupId>
206+
<artifactId>feign-micrometer</artifactId>
207+
</dependency>
202208
```
203-
<!-- Enables tracing of REST API calls made using Feign-->
204-
<dependency>
205-
<groupId>io.github.openfeign</groupId>
206-
<artifactId>feign-micrometer</artifactId>
207-
</dependency>
209+
> Starting with **Spring Boot 4**, the recommended way to call external APIs is to use **RestClient**, as **RestTemplate** is planned for deprecation.
210+
211+
Reference Link: https://spring.io/blog/2025/09/30/the-state-of-http-clients-in-spring#the-future-of-http-clients-in-spring
212+
213+
To use **RestClient**, you need to add the **HTTP Client** starter in `start.spring.io`.
214+
215+
Follow these steps:
216+
217+
1. Open **start.spring.io**
218+
2. Click **Add Dependencies**
219+
3. Type `client` in the search box
220+
4. Select **HTTP Client** from the list
221+
222+
```xml
223+
<dependency>
224+
<groupId>org.springframework.boot</groupId>
225+
<artifactId>spring-boot-starter-restclient</artifactId>
226+
</dependency>
208227
```
209228

210229
CurrencyConversionController.java
211230
```
231+
// Enable for Spring Boot 3.0.x
232+
//@Configuration(proxyBeanMethods = false)
233+
//class RestTemplateConfiguration {
234+
//
235+
// @Bean
236+
// RestTemplate restTemplate(RestTemplateBuilder builder) {
237+
// return builder.build();
238+
// }
239+
//}
240+
212241
@Configuration(proxyBeanMethods = false)
213-
class RestTemplateConfiguration {
214-
242+
class RestClientConfiguration {
243+
215244
@Bean
216-
RestTemplate restTemplate(RestTemplateBuilder builder) {
245+
RestClient restClient(RestClient.Builder builder) {
217246
return builder.build();
218247
}
219248
}
@@ -224,8 +253,12 @@ public class CurrencyConversionController {
224253
@Autowired
225254
private CurrencyExchangeProxy proxy;
226255
227-
@Autowired
228-
private RestTemplate restTemplate;
256+
// Uncomment for Spring Boot 3.0.x
257+
// @Autowired
258+
// private RestTemplate restTemplate;
259+
260+
@Autowired
261+
private RestClient restClient;
229262
230263
```
231264

04.docker/api-gateway/pom.xml

Lines changed: 8 additions & 12 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>
@@ -75,13 +75,17 @@
7575
<artifactId>opentelemetry-exporter-zipkin</artifactId>
7676
</dependency>
7777

78-
7978
<dependency>
8079
<groupId>org.springframework.boot</groupId>
8180
<artifactId>spring-boot-devtools</artifactId>
8281
<scope>runtime</scope>
8382
<optional>true</optional>
8483
</dependency>
84+
<dependency>
85+
<groupId>org.springframework.boot</groupId>
86+
<artifactId>spring-boot-starter-actuator-test</artifactId>
87+
<scope>test</scope>
88+
</dependency>
8589
<dependency>
8690
<groupId>org.springframework.boot</groupId>
8791
<artifactId>spring-boot-starter-test</artifactId>
@@ -116,12 +120,4 @@
116120
</plugins>
117121
</build>
118122

119-
<repositories>
120-
<repository>
121-
<id>spring-milestones</id>
122-
<name>Spring Milestones</name>
123-
<url>https://repo.spring.io/milestone</url>
124-
</repository>
125-
</repositories>
126-
127123
</project>

04.docker/currency-conversion-service/pom.xml

Lines changed: 14 additions & 16 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,7 +26,7 @@
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>
3131
<!-- <dependency>
3232
<groupId>org.springframework.cloud</groupId>
@@ -93,11 +93,16 @@
9393
<scope>runtime</scope>
9494
<optional>true</optional>
9595
</dependency>
96-
<dependency>
97-
<groupId>org.springframework.boot</groupId>
98-
<artifactId>spring-boot-starter-test</artifactId>
99-
<scope>test</scope>
100-
</dependency>
96+
<dependency>
97+
<groupId>org.springframework.boot</groupId>
98+
<artifactId>spring-boot-starter-actuator-test</artifactId>
99+
<scope>test</scope>
100+
</dependency>
101+
<dependency>
102+
<groupId>org.springframework.boot</groupId>
103+
<artifactId>spring-boot-starter-webmvc-test</artifactId>
104+
<scope>test</scope>
105+
</dependency>
101106
</dependencies>
102107

103108
<dependencyManagement>
@@ -127,12 +132,5 @@
127132
</plugins>
128133
</build>
129134

130-
<repositories>
131-
<repository>
132-
<id>spring-milestones</id>
133-
<name>Spring Milestones</name>
134-
<url>https://repo.spring.io/milestone</url>
135-
</repository>
136-
</repositories>
137135

138136
</project>

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

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,21 @@
1313
import org.springframework.web.bind.annotation.RestController;
1414
import org.springframework.web.client.RestTemplate;
1515

16+
// Enable for Spring Boot 3.0.x
17+
//@Configuration(proxyBeanMethods = false)
18+
//class RestTemplateConfiguration {
19+
//
20+
// @Bean
21+
// RestTemplate restTemplate(RestTemplateBuilder builder) {
22+
// return builder.build();
23+
// }
24+
//}
25+
1626
@Configuration(proxyBeanMethods = false)
17-
class RestTemplateConfiguration {
18-
27+
class RestClientConfiguration {
28+
1929
@Bean
20-
RestTemplate restTemplate(RestTemplateBuilder builder) {
30+
RestClient restClient(RestClient.Builder builder) {
2131
return builder.build();
2232
}
2333
}
@@ -28,8 +38,12 @@ public class CurrencyConversionController {
2838
@Autowired
2939
private CurrencyExchangeProxy proxy;
3040

31-
@Autowired
32-
private RestTemplate restTemplate;
41+
// Uncomment for Spring Boot 3.0.x
42+
// @Autowired
43+
// private RestTemplate restTemplate;
44+
45+
@Autowired
46+
private RestClient restClient;
3347

3448
@GetMapping("/currency-conversion/from/{from}/to/{to}/quantity/{quantity}")
3549
public CurrencyConversion calculateCurrencyConversion(
@@ -41,18 +55,23 @@ public CurrencyConversion calculateCurrencyConversion(
4155
HashMap<String, String> uriVariables = new HashMap<>();
4256
uriVariables.put("from",from);
4357
uriVariables.put("to",to);
44-
45-
ResponseEntity<CurrencyConversion> responseEntity = restTemplate.getForEntity
46-
("http://localhost:8000/currency-exchange/from/{from}/to/{to}",
47-
CurrencyConversion.class, uriVariables);
48-
49-
CurrencyConversion currencyConversion = responseEntity.getBody();
50-
51-
return new CurrencyConversion(currencyConversion.getId(),
52-
from, to, quantity,
53-
currencyConversion.getConversionMultiple(),
54-
quantity.multiply(currencyConversion.getConversionMultiple()),
55-
currencyConversion.getEnvironment()+ " " + "rest template");
58+
59+
// ResponseEntity<CurrencyConversion> responseEntity = restTemplate.getForEntity
60+
// ("http://localhost:8000/currency-exchange/from/{from}/to/{to}",
61+
// CurrencyConversion.class, uriVariables);
62+
63+
CurrencyConversion currencyConversion = restClient.get()
64+
.uri("http://localhost:8000/currency-exchange/from/{from}/to/{to}", uriVariables)
65+
.retrieve()
66+
.body(CurrencyConversion.class);
67+
68+
// CurrencyConversion currencyConversion = responseEntity.getBody();
69+
70+
return new CurrencyConversion(currencyConversion.getId(),
71+
from, to, quantity,
72+
currencyConversion.getConversionMultiple(),
73+
quantity.multiply(currencyConversion.getConversionMultiple()),
74+
currencyConversion.getEnvironment()+ " " + "rest client");
5675

5776
}
5877

04.docker/currency-exchange-service/pom.xml

Lines changed: 14 additions & 16 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>
@@ -27,7 +27,7 @@
2727
</dependency>
2828
<dependency>
2929
<groupId>org.springframework.boot</groupId>
30-
<artifactId>spring-boot-starter-web</artifactId>
30+
<artifactId>spring-boot-starter-webmvc</artifactId>
3131
</dependency>
3232
<dependency>
3333
<groupId>org.springframework.boot</groupId>
@@ -102,11 +102,16 @@
102102
<scope>runtime</scope>
103103
<optional>true</optional>
104104
</dependency>
105-
<dependency>
106-
<groupId>org.springframework.boot</groupId>
107-
<artifactId>spring-boot-starter-test</artifactId>
108-
<scope>test</scope>
109-
</dependency>
105+
<dependency>
106+
<groupId>org.springframework.boot</groupId>
107+
<artifactId>spring-boot-starter-actuator-test</artifactId>
108+
<scope>test</scope>
109+
</dependency>
110+
<dependency>
111+
<groupId>org.springframework.boot</groupId>
112+
<artifactId>spring-boot-starter-webmvc-test</artifactId>
113+
<scope>test</scope>
114+
</dependency>
110115
</dependencies>
111116

112117
<dependencyManagement>
@@ -136,12 +141,5 @@
136141
</plugins>
137142
</build>
138143

139-
<repositories>
140-
<repository>
141-
<id>spring-milestones</id>
142-
<name>Spring Milestones</name>
143-
<url>https://repo.spring.io/milestone</url>
144-
</repository>
145-
</repositories>
146144

147145
</project>

04.docker/naming-server/pom.xml

Lines changed: 3 additions & 10 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>
@@ -75,12 +75,5 @@
7575
</plugins>
7676
</build>
7777

78-
<repositories>
79-
<repository>
80-
<id>spring-milestones</id>
81-
<name>Spring Milestones</name>
82-
<url>https://repo.spring.io/milestone</url>
83-
</repository>
84-
</repositories>
8578

8679
</project>

0 commit comments

Comments
 (0)