Skip to content

Commit f913627

Browse files
meysholdtona-agent
andcommitted
Upgrade Spring Boot to 4.0.0
- Update Spring Boot parent version from 3.5.0 to 4.0.0 - Update Java version from 17 to 21 - Rename spring-boot-starter-web to spring-boot-starter-webmvc - Update package imports for Spring Boot 4.0 modularization - Replace RestTemplateBuilder/TestRestTemplate with RestClient - Add new test dependencies for modular test slices - Update plugin versions for compatibility Co-authored-by: Ona <[email protected]>
1 parent 0cc7646 commit f913627

12 files changed

Lines changed: 71 additions & 73 deletions

File tree

build.gradle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
plugins {
22
id 'java'
33
id 'checkstyle'
4-
id 'org.springframework.boot' version '3.5.0'
4+
id 'org.springframework.boot' version '4.0.0'
55
id 'io.spring.dependency-management' version '1.1.7'
6-
id 'org.graalvm.buildtools.native' version '0.10.6'
7-
id 'org.cyclonedx.bom' version '2.3.1'
8-
id 'io.spring.javaformat' version '0.0.46'
6+
id 'org.graalvm.buildtools.native' version '0.11.0'
7+
id 'org.cyclonedx.bom' version '3.0.0'
8+
id 'io.spring.javaformat' version '0.0.47'
99
id "io.spring.nohttp" version "0.0.11"
1010
}
1111

1212
gradle.startParameter.excludedTaskNames += [ "checkFormatAot", "checkFormatAotTest" ]
1313

1414
group = 'org.springframework.samples'
15-
version = '3.5.0'
15+
version = '4.0.0'
1616

1717
java {
1818
toolchain {
19-
languageVersion = JavaLanguageVersion.of(17)
19+
languageVersion = JavaLanguageVersion.of(21)
2020
}
2121
}
2222

@@ -25,7 +25,7 @@ repositories {
2525
}
2626

2727
ext.checkstyleVersion = "10.25.0"
28-
ext.springJavaformatCheckstyleVersion = "0.0.46"
28+
ext.springJavaformatCheckstyleVersion = "0.0.47"
2929
ext.webjarsLocatorLiteVersion = "1.1.0"
3030
ext.webjarsFontawesomeVersion = "4.7.0"
3131
ext.webjarsBootstrapVersion = "5.3.6"
@@ -34,7 +34,7 @@ dependencies {
3434
implementation 'org.springframework.boot:spring-boot-starter-cache'
3535
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
3636
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
37-
implementation 'org.springframework.boot:spring-boot-starter-web'
37+
implementation 'org.springframework.boot:spring-boot-starter-webmvc'
3838
implementation 'org.springframework.boot:spring-boot-starter-validation'
3939
implementation 'javax.cache:cache-api'
4040
implementation 'jakarta.xml.bind:jakarta.xml.bind-api'

pom.xml

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
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></relativePath>
1010
</parent>
1111

1212
<groupId>org.springframework.samples</groupId>
1313
<artifactId>spring-petclinic</artifactId>
14-
<version>3.5.0-SNAPSHOT</version>
14+
<version>4.0.0-SNAPSHOT</version>
1515

1616
<name>petclinic</name>
1717

1818
<properties>
1919

2020
<!-- Generic properties -->
21-
<java.version>17</java.version>
21+
<java.version>21</java.version>
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2323
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2424
<!-- Important for reproducible builds. Update using e.g. ./mvnw versions:set -DnewVersion=... -->
@@ -35,7 +35,8 @@
3535
<lifecycle-mapping>1.0.0</lifecycle-mapping>
3636
<maven-checkstyle.version>3.6.0</maven-checkstyle.version>
3737
<nohttp-checkstyle.version>0.0.11</nohttp-checkstyle.version>
38-
<spring-format.version>0.0.46</spring-format.version>
38+
<spring-format.version>0.0.47</spring-format.version>
39+
<testcontainers.version>1.21.3</testcontainers.version>
3940

4041
</properties>
4142

@@ -55,7 +56,7 @@
5556
</dependency>
5657
<dependency>
5758
<groupId>org.springframework.boot</groupId>
58-
<artifactId>spring-boot-starter-web</artifactId>
59+
<artifactId>spring-boot-starter-webmvc</artifactId>
5960
</dependency>
6061
<dependency>
6162
<groupId>org.springframework.boot</groupId>
@@ -70,6 +71,21 @@
7071
<artifactId>spring-boot-starter-test</artifactId>
7172
<scope>test</scope>
7273
</dependency>
74+
<dependency>
75+
<groupId>org.springframework.boot</groupId>
76+
<artifactId>spring-boot-webmvc-test</artifactId>
77+
<scope>test</scope>
78+
</dependency>
79+
<dependency>
80+
<groupId>org.springframework.boot</groupId>
81+
<artifactId>spring-boot-data-jpa-test</artifactId>
82+
<scope>test</scope>
83+
</dependency>
84+
<dependency>
85+
<groupId>org.springframework.boot</groupId>
86+
<artifactId>spring-boot-restclient-test</artifactId>
87+
<scope>test</scope>
88+
</dependency>
7389

7490
<!-- Databases - Uses H2 by default -->
7591
<dependency>
@@ -133,11 +149,13 @@
133149
<dependency>
134150
<groupId>org.testcontainers</groupId>
135151
<artifactId>junit-jupiter</artifactId>
152+
<version>${testcontainers.version}</version>
136153
<scope>test</scope>
137154
</dependency>
138155
<dependency>
139156
<groupId>org.testcontainers</groupId>
140157
<artifactId>mysql</artifactId>
158+
<version>${testcontainers.version}</version>
141159
<scope>test</scope>
142160
</dependency>
143161

src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.samples.petclinic.system;
1818

19-
import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer;
19+
import org.springframework.boot.cache.autoconfigure.JCacheManagerCustomizer;
2020
import org.springframework.cache.annotation.EnableCaching;
2121
import org.springframework.context.annotation.Bean;
2222
import org.springframework.context.annotation.Configuration;

src/test/java/org/springframework/samples/petclinic/MySqlIntegrationTests.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@
2525
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
2626
import org.springframework.boot.test.web.server.LocalServerPort;
2727
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
28-
import org.springframework.boot.web.client.RestTemplateBuilder;
2928
import org.springframework.http.HttpStatus;
30-
import org.springframework.http.RequestEntity;
3129
import org.springframework.http.ResponseEntity;
3230
import org.springframework.samples.petclinic.vet.VetRepository;
3331
import org.springframework.test.context.ActiveProfiles;
3432
import org.springframework.test.context.aot.DisabledInAotMode;
35-
import org.springframework.web.client.RestTemplate;
33+
import org.springframework.web.client.RestClient;
3634
import org.testcontainers.containers.MySQLContainer;
3735
import org.testcontainers.junit.jupiter.Container;
3836
import org.testcontainers.junit.jupiter.Testcontainers;
@@ -55,9 +53,6 @@ class MySqlIntegrationTests {
5553
@Autowired
5654
private VetRepository vets;
5755

58-
@Autowired
59-
private RestTemplateBuilder builder;
60-
6156
@Test
6257
void testFindAll() {
6358
vets.findAll();
@@ -66,8 +61,8 @@ void testFindAll() {
6661

6762
@Test
6863
void testOwnerDetails() {
69-
RestTemplate template = builder.rootUri("http://localhost:" + port).build();
70-
ResponseEntity<String> result = template.exchange(RequestEntity.get("/owners/1").build(), String.class);
64+
RestClient restClient = RestClient.builder().baseUrl("http://localhost:" + port).build();
65+
ResponseEntity<String> result = restClient.get().uri("/owners/1").retrieve().toEntity(String.class);
7166
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
7267
}
7368

src/test/java/org/springframework/samples/petclinic/PetClinicIntegrationTests.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@
2424
import org.springframework.boot.test.context.SpringBootTest;
2525
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
2626
import org.springframework.boot.test.web.server.LocalServerPort;
27-
import org.springframework.boot.web.client.RestTemplateBuilder;
2827
import org.springframework.http.HttpStatus;
29-
import org.springframework.http.RequestEntity;
3028
import org.springframework.http.ResponseEntity;
3129
import org.springframework.samples.petclinic.vet.VetRepository;
32-
import org.springframework.web.client.RestTemplate;
30+
import org.springframework.web.client.RestClient;
3331

3432
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
3533
public class PetClinicIntegrationTests {
@@ -40,9 +38,6 @@ public class PetClinicIntegrationTests {
4038
@Autowired
4139
private VetRepository vets;
4240

43-
@Autowired
44-
private RestTemplateBuilder builder;
45-
4641
@Test
4742
void testFindAll() {
4843
vets.findAll();
@@ -51,8 +46,8 @@ void testFindAll() {
5146

5247
@Test
5348
void testOwnerDetails() {
54-
RestTemplate template = builder.rootUri("http://localhost:" + port).build();
55-
ResponseEntity<String> result = template.exchange(RequestEntity.get("/owners/1").build(), String.class);
49+
RestClient restClient = RestClient.builder().baseUrl("http://localhost:" + port).build();
50+
ResponseEntity<String> result = restClient.get().uri("/owners/1").retrieve().toEntity(String.class);
5651
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
5752
}
5853

src/test/java/org/springframework/samples/petclinic/PostgresIntegrationTests.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,15 @@
3535
import org.springframework.boot.test.context.SpringBootTest;
3636
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
3737
import org.springframework.boot.test.web.server.LocalServerPort;
38-
import org.springframework.boot.web.client.RestTemplateBuilder;
3938
import org.springframework.context.ApplicationListener;
4039
import org.springframework.core.env.ConfigurableEnvironment;
4140
import org.springframework.core.env.EnumerablePropertySource;
4241
import org.springframework.core.env.PropertySource;
4342
import org.springframework.http.HttpStatus;
44-
import org.springframework.http.RequestEntity;
4543
import org.springframework.http.ResponseEntity;
4644
import org.springframework.samples.petclinic.vet.VetRepository;
4745
import org.springframework.test.context.ActiveProfiles;
48-
import org.springframework.web.client.RestTemplate;
46+
import org.springframework.web.client.RestClient;
4947
import org.testcontainers.DockerClientFactory;
5048

5149
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "spring.docker.compose.skip.in-tests=false", //
@@ -60,9 +58,6 @@ public class PostgresIntegrationTests {
6058
@Autowired
6159
private VetRepository vets;
6260

63-
@Autowired
64-
private RestTemplateBuilder builder;
65-
6661
@BeforeAll
6762
static void available() {
6863
assumeTrue(DockerClientFactory.instance().isDockerAvailable(), "Docker not available");
@@ -86,8 +81,8 @@ void testFindAll() throws Exception {
8681

8782
@Test
8883
void testOwnerDetails() {
89-
RestTemplate template = builder.rootUri("http://localhost:" + port).build();
90-
ResponseEntity<String> result = template.exchange(RequestEntity.get("/owners/1").build(), String.class);
84+
RestClient restClient = RestClient.builder().baseUrl("http://localhost:" + port).build();
85+
ResponseEntity<String> result = restClient.get().uri("/owners/1").retrieve().toEntity(String.class);
9186
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
9287
}
9388

src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.junit.jupiter.api.Test;
2121
import org.junit.jupiter.api.condition.DisabledInNativeImage;
2222
import org.springframework.beans.factory.annotation.Autowired;
23-
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
23+
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
2424
import org.springframework.data.domain.Page;
2525
import org.springframework.data.domain.PageImpl;
2626
import org.springframework.data.domain.Pageable;

src/test/java/org/springframework/samples/petclinic/owner/PetControllerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.junit.jupiter.api.Test;
2222
import org.junit.jupiter.api.condition.DisabledInNativeImage;
2323
import org.springframework.beans.factory.annotation.Autowired;
24-
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
24+
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
2525
import org.springframework.context.annotation.ComponentScan;
2626
import org.springframework.context.annotation.FilterType;
2727
import org.springframework.samples.petclinic.owner.PetTypeRepository;

src/test/java/org/springframework/samples/petclinic/owner/VisitControllerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.junit.jupiter.api.Test;
2828
import org.junit.jupiter.api.condition.DisabledInNativeImage;
2929
import org.springframework.beans.factory.annotation.Autowired;
30-
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
30+
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
3131
import org.springframework.test.context.aot.DisabledInAotMode;
3232
import org.springframework.test.context.bean.override.mockito.MockitoBean;
3333
import org.springframework.test.web.servlet.MockMvc;

src/test/java/org/springframework/samples/petclinic/service/ClinicServiceTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
import org.junit.jupiter.api.Test;
2626
import org.springframework.beans.factory.annotation.Autowired;
27-
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
28-
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace;
29-
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
27+
import org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureTestDatabase;
28+
import org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureTestDatabase.Replace;
29+
import org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest;
3030
import org.springframework.data.domain.Page;
3131
import org.springframework.data.domain.Pageable;
3232
import org.springframework.samples.petclinic.owner.Owner;

0 commit comments

Comments
 (0)