Migration to Java 21 and Spring Boot 3.4
Please add any missing hints to this document!
See TC’s approved Officially Supported Technologies / Sunflower document.
Help
Ask on #development Slack channel if a module doesn’t build on Java 21 and/or Spring Boot 3.4.
Jenkinsfile
In Jenkinsfile change the buildNode from java17 to java21:
buildNode = 'jenkins-agent-java21'
Dockerfile
In Dockerfile change the container from opendjk17 to openjdk21:
FROM folioci/alpine-jre-openjdk21:latest
For details see https://github.com/folio-org/folio-tools/tree/master/folio-java-docker/openjdk21
GitHub Actions
A few projects use a Java in GitHub Actions workflow, check the .github/workflows
directory. Upgrade java-version from 17 to 21:
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
POM Files
If declared, be sure to change the Java version and source/target compilation versions. This can be done under the main properties block:
<java.version>21</java.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
Note: for this to work, be sure that the source/target versions are not overridden in the maven-compiler-plugin
configuration.
Mockito
See https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#0.3 how to enable instrumentation of Mockito’s inline-mock-maker if it doesn’t work with Java 21.
Snippets that also work in IDEs:
<properties>
<argLine></argLine>
<mockito.version>5.16.0</mockito.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.2</version>
<configuration>
<argLine>
@{argLine}
-javaagent:${settings.localRepository}/org/mockito/mockito-core/${mockito.version}/mockito-core-${mockito.version}.jar
-Xshare:off
</argLine>
</configuration>
</plugin>
</plugins>
</build>
Spring Boot
Upgrade the spring-boot-starter-parent version to the latest 3.4 version, find the version on https://github.com/spring-projects/spring-boot/tags
Replace javax.annotation.PostConstruct
with jakarta.annotation.PostConstruct
.
Add null
argument to buildConsumerProperties()
and buildProducerProperties()
of KafkaProperties (example).
Replace @MockBean
with @MockitoBean
and @SpyBean
with MockitoSpyBean
.
Change Actuator settings management.endpoints.enabled-by-default
to management.endpoints.access.default
(The Boolean values change to none
, read-only
, and unrestricted
).
Change Actuator settings from management.endpoint.<id>.enabled
to management.endpoint.<id>.access
.
The Spring-Boot-3.4-Release-Notes describe further details useful for migration.
ObjectOptimisticLockingFailureException
After upgrade to Spring Boot 3.4 some tests fail with
org.springframework.orm.ObjectOptimisticLockingFailureException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)
if an entity has
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;
and tests initialize the id with some UUID.
Solution: Set id to null, or don’t initialize it.
Learn more at https://stackoverflow.com/questions/79228209/spring-boot-3-4-0-lets-integration-tests-with-jpa-hibernate-fail
Openfeign
spring-cloud-starter-openfeign 4.2.x is required for Spring Boot 3.4.x, use the latest patch version: https://github.com/spring-cloud/spring-cloud-openfeign/tags
Migrated repositories
https://folio-org.atlassian.net/browse/FOLIO-4182 – Epic Sunflower 2025 R1 - Upgrade to Java 21 and Spring Boot 3.4
In August 2024 some FOLIO modules and FOLIO libraries have had been migrated to Spring Boot 3.4 as a proof of concept to demonstrate that only small changes are needed:
Build result: success | |
https://github.com/folio-org/mod-circulation-item/pull/29/files | Build result: success |
Build result: success | |
Build result: success | |
https://github.com/folio-org/mod-search/compare/master...julianladisch:mod-search:spring-boot-3.4 | Build result: success |
Build result: success | |
Build result: success |
What is Spring Boot’s milestone and release candidate history?
v3.5.x:
2025-01-23 v3.5.0-M1
v3.4.x:
2024-11-21 v3.4.0
2024-10-26 v3.4.0-RC1
2024-09-19 v3.4.0-M3
2024-08-22 v3.4.0-M2
2024-07-18 v3.4.0-M1
v3.3.x:
2024-05-23 v3.3.0
2024-04-19 v3.3.0-RC1
2024-04-05 v3.3.0-M3
2024-02-22 v3.3.0-M2
2024-01-19 v3.3.0-M1
v3.2.x:
2023-11-23 v3.2.0
2023-11-03 v3.2.0-RC2
2023-10-20 v3.2.0-RC1
2023-09-21 v3.2.0-M3
2023-08-24 v3.2.0-M2
2023-07-20 v3.2.0-M1
v3.1.x:
2023-05-19 v3.1.0
2023-05-05 v3.1.0-RC2
2023-04-22 v3.1.0-RC1
2023-04-24 v3.1.0-M2
2023-02-24 v3.1.0-M1
Spring Boot has always been released on the planned date.