Skip to content

Commit 920a3ef

Browse files
committed
Upgrade to Spring boot 4
1 parent a5be765 commit 920a3ef

File tree

10 files changed

+611
-479
lines changed

10 files changed

+611
-479
lines changed

build.gradle.kts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import com.google.protobuf.gradle.id
22

33
plugins {
4-
id("org.springframework.boot") version "3.5.8"
4+
id("org.springframework.boot") version "4.0.0"
55
id("io.spring.dependency-management") version "1.1.7"
66
id("org.graalvm.buildtools.native") version "0.11.1"
77
id("org.jetbrains.kotlin.jvm") version "2.2.21"
@@ -26,22 +26,21 @@ repositories {
2626
mavenCentral()
2727
}
2828

29-
extra["testcontainersVersion"] = "2.0.2"
30-
extra["jjwtVersion"] = "0.12.6"
29+
extra["testcontainersVersion"] = "1.21.3"
30+
extra["jjwtVersion"] = "0.13.0"
3131

3232
dependencies {
3333
// Spring Boot Starters
34-
implementation("org.springframework.boot:spring-boot-starter-web") {
35-
exclude(group = "org.springframework.boot", module = "spring-boot-starter-tomcat")
36-
}
37-
implementation("org.springframework.boot:spring-boot-starter-undertow")
34+
implementation("org.springframework.boot:spring-boot-starter-webmvc")
3835
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
3936
implementation("org.springframework.boot:spring-boot-starter-security")
4037
implementation("org.springframework.boot:spring-boot-starter-validation")
4138
implementation("org.springframework.boot:spring-boot-starter-actuator")
42-
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.14")
39+
implementation("org.springframework.boot:spring-boot-starter-jackson")
40+
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:3.0.0")
4341

4442
// Database
43+
implementation("org.springframework.boot:spring-boot-starter-flyway")
4544
runtimeOnly("org.postgresql:postgresql:42.7.8")
4645
runtimeOnly("org.flywaydb:flyway-database-postgresql:11.11.1")
4746

@@ -56,31 +55,28 @@ dependencies {
5655
developmentOnly("org.springframework.boot:spring-boot-docker-compose")
5756

5857
// Testing
59-
testImplementation("org.springframework.boot:spring-boot-starter-test") {
60-
exclude(group = "junit", module = "junit")
61-
}
58+
testImplementation("org.springframework.boot:spring-boot-starter-webmvc-test")
59+
testImplementation("org.springframework.boot:spring-boot-starter-webflux-test") // For WebTestClient
60+
testImplementation("org.springframework.boot:spring-boot-starter-data-jpa-test")
6261
testImplementation("org.springframework.security:spring-security-test")
6362
testImplementation("org.springframework.boot:spring-boot-testcontainers")
6463
testImplementation("org.junit.jupiter:junit-jupiter:5.13.3")
6564
testImplementation("org.testcontainers:junit-jupiter")
6665
testImplementation("org.testcontainers:postgresql")
67-
testImplementation("io.rest-assured:rest-assured:5.5.6")
68-
testImplementation("io.rest-assured:json-path:5.5.6")
6966

7067
// Swagger
7168
implementation("io.swagger.core.v3:swagger-models:2.2.34")
7269
implementation("io.swagger.core.v3:swagger-core:2.2.34")
73-
implementation("javax.xml.bind:jaxb-api:2.3.1")
74-
implementation("com.sun.xml.bind:jaxb-impl:2.3.9")
70+
implementation("jakarta.xml.bind:jakarta.xml.bind-api:4.0.2")
71+
runtimeOnly("org.glassfish.jaxb:jaxb-runtime:4.0.5")
7572

7673
// gRPC and Protobuf
7774
implementation("io.grpc:grpc-netty-shaded:1.77.0")
7875
implementation("io.grpc:grpc-protobuf:1.77.0")
7976
implementation("io.grpc:grpc-stub:1.77.0")
8077
implementation("com.google.protobuf:protobuf-java:4.33.1")
81-
// Because protobuf is still using javax annotations
82-
implementation("javax.annotation:javax.annotation-api:1.3.2")
83-
implementation("net.devh:grpc-server-spring-boot-starter:3.1.0.RELEASE")
78+
implementation("jakarta.annotation:jakarta.annotation-api:3.0.0")
79+
implementation("org.springframework.grpc:spring-grpc-spring-boot-starter:1.0.0")
8480
}
8581

8682
dependencyManagement {

docs/troubleshooting.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22

33
Move `@EnableJpaAuditing` to a separate configuration class `JpaAuditingConfig.java` so that we can exclude it from
44
testings. Otherwise it will throw errors when testing controllers:
5+
56
```
67
Caused by: java.lang.IllegalArgumentException: JPA metamodel must not be empty
78
at org.springframework.util.Assert.notEmpty(Assert.java:398)
89
```
10+
11+
## Rest Assured - not support Spring Boot 4
12+
13+
Rest Assured 5.5.6 doesn't work with Groovy 5 (still use Groovy 4), which is not compatible with Spring Boot 4(uses
14+
Groovy 5).
15+
We need to replace Rest Assured with `WebTestClient` before Rest Assured's upgrade.
16+
17+
- [Remove integration for REST Docs' REST Assured support until REST Assured supports Groovy 5](https://github.com/spring-projects/spring-boot/issues/47685)
18+
- [Drop support for REST Assured until it supports Groovy 5](https://github.com/spring-projects/spring-restdocs/issues/1000)

gradle/jacoco.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ val strictCoverageClasses = listOf(
6161
)
6262

6363
tasks.named<JacocoReport>("jacocoTestReport") {
64-
dependsOn(tasks.named("test"))
64+
dependsOn(tasks.named("test"), tasks.named("processResources"), tasks.named("compileJava"))
6565
reports {
6666
xml.required.set(true) // For CI/CD integration
6767
html.required.set(true) // For human-readable reports

src/main/java/org/nkcoder/infrastructure/config/ObservabilityConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import io.micrometer.core.aop.TimedAspect;
44
import io.micrometer.core.instrument.MeterRegistry;
55
import io.micrometer.core.instrument.config.MeterFilter;
6-
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
6+
import org.springframework.boot.micrometer.metrics.autoconfigure.MeterRegistryCustomizer;
77
import org.springframework.context.annotation.Bean;
88
import org.springframework.context.annotation.Configuration;
99

src/main/java/org/nkcoder/infrastructure/security/JwtAuthenticationEntryPoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.nkcoder.infrastructure.security;
22

3-
import com.fasterxml.jackson.databind.ObjectMapper;
43
import io.jsonwebtoken.ExpiredJwtException;
54
import jakarta.servlet.http.HttpServletRequest;
65
import jakarta.servlet.http.HttpServletResponse;
@@ -13,6 +12,7 @@
1312
import org.springframework.security.core.AuthenticationException;
1413
import org.springframework.security.web.AuthenticationEntryPoint;
1514
import org.springframework.stereotype.Component;
15+
import tools.jackson.databind.ObjectMapper;
1616

1717
@Component
1818
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {

src/main/resources/application.yml

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,23 @@ spring:
2727
fetch_size: 100
2828
generate_statistics: false
2929

30-
security:
31-
oauth2:
32-
resourceserver:
33-
jwt:
34-
issuer-uri: http://localhost:3001
35-
36-
jackson:
37-
serialization:
38-
write-dates-as-timestamps: false
39-
time-zone: UTC
40-
property-naming-strategy: LOWER_CAMEL_CASE
41-
42-
autoconfigure:
43-
exclude:
44-
- org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration
45-
4630
docker:
4731
compose:
4832
enabled: false
33+
4934
threads:
5035
virtual:
5136
enabled: true
5237

38+
# gRPC configuration
39+
grpc:
40+
server:
41+
port: 9090
42+
max-inbound-message-size: 4MB
43+
max-inbound-metadata-size: 8KB
44+
reflection:
45+
enabled: true
46+
5347
# JWT Configuration
5448
jwt:
5549
secret:
@@ -68,10 +62,6 @@ cors:
6862
allow-credentials: true
6963
max-age: 3600
7064

71-
# Rate Limiting Configuration
72-
rate-limit:
73-
requests-per-window: 100
74-
window-size-minutes: 15
7565

7666
# Actuator Configuration
7767
management:
@@ -117,12 +107,4 @@ info:
117107
version: '@project.version@'
118108
description: '@project.description@'
119109
java-version: '@java.version@'
120-
spring-boot-version: '@parent.version@'
121-
122-
# grpc configuration
123-
grpc:
124-
server:
125-
port: 9090
126-
max-inbound-message-size: 4194304 # 4MB
127-
max-inbound-metadata-size: 8192 # 8KB
128-
reflection-service-enabled: true
110+
spring-boot-version: '@parent.version@'

src/test/java/org/nkcoder/infrastructure/config/DataJpaIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import java.lang.annotation.Retention;
55
import java.lang.annotation.RetentionPolicy;
66
import java.lang.annotation.Target;
7-
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
8-
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
7+
import org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest;
8+
import org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureTestDatabase;
99
import org.springframework.context.annotation.Import;
1010
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
1111
import org.springframework.test.context.ActiveProfiles;

0 commit comments

Comments
 (0)