Skip to content

Commit e419805

Browse files
feat : Upgrade to spring boot 4 (#2236)
* feat : Upgrade to spring boot 4 * fix compilation issues * review comments addressed * fix issue with step scope value * implement review comments * fix : issue with compilation * fix : cache collision
1 parent ab5ba39 commit e419805

18 files changed

+180
-220
lines changed

poc-rest-api/spring-boot-rest-webmvc/pom.xml

Lines changed: 83 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.springframework.boot</groupId>
99
<artifactId>spring-boot-starter-parent</artifactId>
10-
<version>3.5.11</version>
10+
<version>4.0.3</version>
1111
<relativePath/> <!-- lookup parent from repository -->
1212
</parent>
1313

@@ -18,14 +18,13 @@
1818
<properties>
1919
<java.version>21</java.version>
2020
<org.mapstruct.version>1.6.3</org.mapstruct.version>
21-
<springdoc-open-ui.version>2.8.15</springdoc-open-ui.version>
21+
<springdoc-open-ui.version>3.0.1</springdoc-open-ui.version>
22+
23+
<testcontainers-jooq-codegen-maven-plugin.version>1.0.0</testcontainers-jooq-codegen-maven-plugin.version>
2224

2325
<maven-pmd-plugin.version>3.13.0</maven-pmd-plugin.version>
2426
<dependency-check-maven.version>12.2.0</dependency-check-maven.version>
2527
<spotless.version>3.2.1</spotless.version>
26-
27-
<db.username>local</db.username>
28-
<db.password>local</db.password>
2928
</properties>
3029

3130
<dependencies>
@@ -43,7 +42,7 @@
4342
</dependency>
4443
<dependency>
4544
<groupId>org.springframework.boot</groupId>
46-
<artifactId>spring-boot-starter-web</artifactId>
45+
<artifactId>spring-boot-starter-webmvc</artifactId>
4746
</dependency>
4847
<dependency>
4948
<groupId>org.springframework.boot</groupId>
@@ -66,8 +65,8 @@
6665
<artifactId>caffeine</artifactId>
6766
</dependency>
6867
<dependency>
69-
<groupId>org.liquibase</groupId>
70-
<artifactId>liquibase-core</artifactId>
68+
<groupId>org.springframework.boot</groupId>
69+
<artifactId>spring-boot-starter-liquibase</artifactId>
7170
</dependency>
7271
<dependency>
7372
<groupId>org.mapstruct</groupId>
@@ -102,22 +101,37 @@
102101
</dependency>
103102
<dependency>
104103
<groupId>org.springframework.boot</groupId>
105-
<artifactId>spring-boot-starter-test</artifactId>
104+
<artifactId>spring-boot-starter-webmvc-test</artifactId>
106105
<scope>test</scope>
107106
</dependency>
108107
<dependency>
109-
<groupId>org.springframework.batch</groupId>
110-
<artifactId>spring-batch-test</artifactId>
108+
<groupId>org.springframework.boot</groupId>
109+
<artifactId>spring-boot-starter-batch-test</artifactId>
110+
<scope>test</scope>
111+
</dependency>
112+
<dependency>
113+
<groupId>org.springframework.boot</groupId>
114+
<artifactId>spring-boot-resttestclient</artifactId>
115+
<scope>test</scope>
116+
</dependency>
117+
<dependency>
118+
<groupId>org.springframework.boot</groupId>
119+
<artifactId>spring-boot-starter-data-jpa-test</artifactId>
120+
<scope>test</scope>
121+
</dependency>
122+
<dependency>
123+
<groupId>org.springframework.boot</groupId>
124+
<artifactId>spring-boot-starter-restclient</artifactId>
111125
<scope>test</scope>
112126
</dependency>
113127
<dependency>
114128
<groupId>org.testcontainers</groupId>
115-
<artifactId>junit-jupiter</artifactId>
129+
<artifactId>testcontainers-junit-jupiter</artifactId>
116130
<scope>test</scope>
117131
</dependency>
118132
<dependency>
119133
<groupId>org.testcontainers</groupId>
120-
<artifactId>postgresql</artifactId>
134+
<artifactId>testcontainers-postgresql</artifactId>
121135
<scope>test</scope>
122136
</dependency>
123137
</dependencies>
@@ -215,121 +229,89 @@
215229
<failOnError>false</failOnError>
216230
</configuration>
217231
</plugin>
218-
<!-- Much better if there was a testcontainers lifecycle management plugin!
219-
Upvote here if you like the idea: https://github.com/testcontainers/testcontainers-java/issues/4397 -->
220-
<plugin>
221-
<groupId>org.codehaus.gmaven</groupId>
222-
<artifactId>groovy-maven-plugin</artifactId>
223-
<version>2.1.1</version>
224-
<executions>
225-
<execution>
226-
<phase>generate-sources</phase>
227-
<goals>
228-
<goal>execute</goal>
229-
</goals>
230-
<configuration>
231-
<source>
232-
db = new org.testcontainers.containers.PostgreSQLContainer("postgres:latest")
233-
.withUsername("${db.username}")
234-
.withDatabaseName("rest")
235-
.withPassword("${db.password}");
236232

237-
db.start();
238-
project.properties.setProperty('db.url', db.getJdbcUrl());
239-
</source>
240-
</configuration>
241-
</execution>
242-
</executions>
233+
<plugin>
234+
<groupId>org.apache.maven.plugins</groupId>
235+
<artifactId>maven-surefire-plugin</artifactId>
236+
</plugin>
243237

238+
<plugin>
239+
<groupId>dev.sivalabs</groupId>
240+
<artifactId>testcontainers-jooq-codegen-maven-plugin</artifactId>
241+
<version>${testcontainers-jooq-codegen-maven-plugin.version}</version>
244242
<dependencies>
245243
<dependency>
246244
<groupId>org.testcontainers</groupId>
247-
<artifactId>postgresql</artifactId>
245+
<artifactId>testcontainers-postgresql</artifactId>
248246
<version>${testcontainers.version}</version>
249247
</dependency>
250-
</dependencies>
251-
</plugin>
252-
253-
<plugin>
254-
<groupId>org.flywaydb</groupId>
255-
<artifactId>flyway-maven-plugin</artifactId>
256-
<version>${flyway.version}</version>
257-
<executions>
258-
<execution>
259-
<phase>generate-sources</phase>
260-
<goals>
261-
<goal>migrate</goal>
262-
</goals>
263-
<configuration>
264-
<url>${db.url}</url>
265-
<user>${db.username}</user>
266-
<password>${db.password}</password>
267-
<locations>
268-
<location>filesystem:src/main/resources/db/migration</location>
269-
</locations>
270-
</configuration>
271-
</execution>
272-
</executions>
273-
<dependencies>
274248
<dependency>
275-
<groupId>org.flywaydb</groupId>
276-
<artifactId>flyway-database-postgresql</artifactId>
277-
<version>${flyway.version}</version>
249+
<groupId>org.postgresql</groupId>
250+
<artifactId>postgresql</artifactId>
251+
<version>${postgresql.version}</version>
252+
</dependency>
253+
<dependency>
254+
<groupId>org.jooq</groupId>
255+
<artifactId>jooq-codegen</artifactId>
256+
<version>${jooq.version}</version>
278257
</dependency>
279258
</dependencies>
280-
</plugin>
281-
282-
<plugin>
283-
<groupId>org.jooq</groupId>
284-
<artifactId>jooq-codegen-maven</artifactId>
285-
286259
<executions>
287260
<execution>
288-
<id>java-generator</id>
289-
<phase>generate-sources</phase>
261+
<id>generate-jooq-sources</id>
290262
<goals>
291263
<goal>generate</goal>
292264
</goals>
293-
265+
<phase>generate-sources</phase>
294266
<configuration>
295-
<jdbc>
296-
<url>${db.url}</url>
297-
<user>${db.username}</user>
298-
<password>${db.password}</password>
299-
</jdbc>
300-
<generator>
301-
<database>
302-
<inputSchema>public</inputSchema>
303-
</database>
304-
<target>
305-
<packageName>com.example.poc.webmvc.testcontainersflyway.db</packageName>
306-
<directory>target/generated-sources/jooq</directory>
307-
</target>
308-
</generator>
267+
<database>
268+
<!--
269+
"type" can be: POSTGRES, MYSQL, MARIADB
270+
-->
271+
<type>POSTGRES</type>
272+
<!--
273+
"containerImage" is optional.
274+
The defaults are
275+
POSTGRES: postgres:15.2-alpine
276+
MYSQL: mysql:8.0.33
277+
MARIADB: mariadb:10.11
278+
-->
279+
<containerImage>postgres:18.2-alpine</containerImage>
280+
</database>
281+
<flyway>
282+
<locations>
283+
filesystem:src/main/resources/db/migration
284+
</locations>
285+
</flyway>
286+
<!--
287+
You can configure any supporting jooq config here.
288+
see https://www.jooq.org/doc/latest/manual/code-generation/codegen-configuration/
289+
-->
290+
<jooq>
291+
<generator>
292+
<database>
293+
<includes>.*</includes>
294+
<excludes>DATABASECHANGELOG.*</excludes>
295+
<inputSchema>public</inputSchema>
296+
</database>
297+
<target>
298+
<packageName>com.example.poc.webmvc.db</packageName>
299+
<directory>target/generated-sources/jooq</directory>
300+
</target>
301+
</generator>
302+
</jooq>
309303
</configuration>
310304
</execution>
311305
</executions>
312306
</plugin>
313-
314-
<plugin>
315-
<groupId>org.apache.maven.plugins</groupId>
316-
<artifactId>maven-surefire-plugin</artifactId>
317-
<configuration>
318-
<systemPropertyVariables>
319-
<db.url>${db.url}</db.url>
320-
<db.username>${db.username}</db.username>
321-
<db.password>${db.password}</db.password>
322-
</systemPropertyVariables>
323-
</configuration>
324-
</plugin>
325307
<plugin>
326308
<groupId>com.diffplug.spotless</groupId>
327309
<artifactId>spotless-maven-plugin</artifactId>
328310
<version>${spotless.version}</version>
329311
<configuration>
330312
<java>
331313
<googleJavaFormat>
332-
<version>1.25.2</version>
314+
<version>1.28.0</version>
333315
<style>AOSP</style>
334316
</googleJavaFormat>
335317
<licenseHeader>
@@ -349,25 +331,4 @@
349331
</plugins>
350332
</build>
351333

352-
<repositories>
353-
<repository>
354-
<id>spring-milestones</id>
355-
<name>Spring Milestones</name>
356-
<url>https://repo.spring.io/milestone</url>
357-
<snapshots>
358-
<enabled>false</enabled>
359-
</snapshots>
360-
</repository>
361-
</repositories>
362-
<pluginRepositories>
363-
<pluginRepository>
364-
<id>spring-milestones</id>
365-
<name>Spring Milestones</name>
366-
<url>https://repo.spring.io/milestone</url>
367-
<snapshots>
368-
<enabled>false</enabled>
369-
</snapshots>
370-
</pluginRepository>
371-
</pluginRepositories>
372-
373334
</project>

poc-rest-api/spring-boot-rest-webmvc/src/main/java/com/example/poc/webmvc/SpringBootRestWebMvcApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import com.example.poc.webmvc.config.ApplicationProperties;
55
import org.springframework.boot.SpringApplication;
66
import org.springframework.boot.autoconfigure.SpringBootApplication;
7-
import org.springframework.boot.autoconfigure.domain.EntityScan;
87
import org.springframework.boot.context.properties.EnableConfigurationProperties;
8+
import org.springframework.boot.persistence.autoconfigure.EntityScan;
99

1010
@SpringBootApplication
1111
@EntityScan(basePackages = {"com.example.poc.webmvc.entities"})

poc-rest-api/spring-boot-rest-webmvc/src/main/java/com/example/poc/webmvc/batch/CustomItemProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import java.util.stream.Collector;
1212
import java.util.stream.Collectors;
1313
import lombok.RequiredArgsConstructor;
14-
import org.springframework.batch.item.ItemProcessor;
14+
import org.springframework.batch.infrastructure.item.ItemProcessor;
1515
import org.springframework.stereotype.Component;
1616

1717
@RequiredArgsConstructor

poc-rest-api/spring-boot-rest-webmvc/src/main/java/com/example/poc/webmvc/batch/CustomItemReader.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,25 @@
77
import java.util.concurrent.CopyOnWriteArrayList;
88
import java.util.concurrent.atomic.AtomicInteger;
99
import java.util.stream.Collectors;
10-
import lombok.RequiredArgsConstructor;
11-
import org.springframework.batch.core.JobParameters;
12-
import org.springframework.batch.core.StepExecution;
13-
import org.springframework.batch.core.annotation.BeforeStep;
14-
import org.springframework.batch.item.database.AbstractPagingItemReader;
10+
import org.springframework.batch.core.configuration.annotation.StepScope;
11+
import org.springframework.batch.infrastructure.item.database.AbstractPagingItemReader;
12+
import org.springframework.beans.factory.annotation.Value;
1513
import org.springframework.stereotype.Component;
14+
import org.springframework.util.CollectionUtils;
1615

17-
@RequiredArgsConstructor
1816
@Component
17+
@StepScope
1918
public class CustomItemReader<T> extends AbstractPagingItemReader<List<Long>> {
2019

2120
private final PostRepository postRepository;
2221

2322
private List<List<Long>> ids = new ArrayList<>();
2423

24+
@Value("#{jobParameters['key']}")
2525
private String titleValue;
2626

27-
@BeforeStep
28-
public void beforeStep(final StepExecution stepExecution) {
29-
JobParameters parameters = stepExecution.getJobExecution().getJobParameters();
30-
// use your parameters
31-
this.titleValue = parameters.getString("key");
27+
public CustomItemReader(PostRepository postRepository) {
28+
this.postRepository = postRepository;
3229
}
3330

3431
@Override
@@ -52,6 +49,10 @@ protected void doReadPage() {
5249
/ getPageSize()))
5350
.values());
5451
}
55-
results.add(this.ids.get(getPage() * getPageSize()));
52+
if (!CollectionUtils.isEmpty(ids)) {
53+
if (getPage() < this.ids.size()) {
54+
results.add(this.ids.get(getPage()));
55+
}
56+
}
5657
}
5758
}

poc-rest-api/spring-boot-rest-webmvc/src/main/java/com/example/poc/webmvc/batch/CustomItemWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import com.example.poc.webmvc.dto.PostDTO;
55
import java.util.List;
66
import lombok.extern.slf4j.Slf4j;
7-
import org.springframework.batch.item.Chunk;
8-
import org.springframework.batch.item.ItemWriter;
7+
import org.springframework.batch.infrastructure.item.Chunk;
8+
import org.springframework.batch.infrastructure.item.ItemWriter;
99
import org.springframework.stereotype.Component;
1010

1111
@Component

0 commit comments

Comments
 (0)