1. Introduction

Datetime

{{CREATION_DATE}}

Project dir

{{PATH_TO_PROJECT}}

Revision

No .git found in project dir

Project name

spring-boot-24-to-25-example

Coordinate

com.example:spring-boot-24-to-25-example:0.0.1-SNAPSHOT

Boot version

2.4.12

Changes

5

The application was scanned and matched against the changes listed in the Spring Boot 2.5 Release Notes as well as from Spring Framework 5.x Release Notes.

The Relevant Changes section lists all potentially required changes to upgrade the scanned application to Spring Boot 2.5.6.

1.1. Automated Migration

Some changes listed in 'Relevant Changes' can be automated.
It is advisable to read through 'Relevant Changes' to see if you want to apply all or just a subset of the applicable recipes.

  • Copy the following list of recipes to a file recipes.txt.

  • Run Spring Boot Migrator and provide the list of recipes:
    java -jar spring-boot-migrator.jar @recipes.txt

scan {{PATH_TO_PROJECT}}
apply boot-2.4-2.5-dependency-version-update
apply boot-2.4-2.5-sql-init-properties
apply boot-2.4-2.5-datasource-initializer
apply boot-2.4-2.5-spring-data-jpa
apply boot-2.4-2.5-upgrade-report

2. Relevant Changes

2.1. Update dependencies

The Spring Boot version must be updated to 2.5.6.

Relevance

The scan found a dependency to Spring Boot 2.4.12 as parent to the Maven build file pom.xml.

Todo

  • ❏ Change the version of the referenced spring-boot-starter-parent in pom.xml from 2.4.12 to 2.5.6.

Tip

🤖 Can be automated 🤖

Apply the recipe boot-2.4-2.5-dependency-version-update.

2.2. SQL Script DataSource Initialization

The underlying method used to support schema.sql and data.sql scripts has been redesigned in Spring Boot 2.5.
spring.datasource.* properties related to DataSource initialization have been deprecated in favor of new spring.sql.init.* properties.
These properties can also be used to initialize an SQL database accessed via R2DBC.

Relevance

The scan found properties in your application that need to be changed as these were deprecated in Spring Boot 2.5.
Please see the table below for more information about what needs to be changed.

File Old (2.4) New (2.5)

target/testcode/spring-boot-2.4-to-2.5-example/src/main/resources/application.properties

spring.datasource.continue-on-error

spring.sql.init.continue-on-error

target/testcode/spring-boot-2.4-to-2.5-example/src/main/resources/application.properties

spring.datasource.platform

spring.sql.init.platform

Todo

  • ❏ Replace the old property names to the new names in the given files.

Tip

🤖 Can be automated 🤖

Apply the recipe boot-2.4-2.5-sql-init-properties.

2.3. schema.sql and data.sql Files

With Spring Boot 2.5.1 and above, the new SQL initialization properties support detection of embedded datasources for JDBC and R2DBC.
By default, SQL database initialization is only performed when using an embedded in-memory database.
To always initialize a SQL database, irrespective of its jpaRepositoryInterface, set spring.sql.init.mode to always.
Similarly, to disable initialization, set spring.sql.init.mode to never.

Relevance

The scan found a dependency to H2 in-memory database in ./pom.xml and the files target/testcode/spring-boot-2.4-to-2.5-example/src/main/resources/data.sql, target/testcode/spring-boot-2.4-to-2.5-example/src/main/resources/schema.sql

Todo

  • ❏ Verify if you need to set the spring.sql.init.mode property to either always or never, embedded being the default.

2.4. Separate Credentials

The new script-based SQL database initialization does not support using separate credentials for schema (DDL) and data (DML) changes.
This reduces complexity and aligns its capabilities with Flyway and Liquibase.
If you require separate credentials for schema and data initialization, define your own org.springframework.jdbc.datasource.init.DataSourceInitializer beans.

Relevance

The scan found the properties spring.datasource.data-username and spring.datasource.schema-username in ./path/to/application.properties.

Todo

You have two options.

1. Use same credentials for data and schema creation (preferred)

  • ❏ Change credentials and provide required access to the database user in all affected databases.

  • ❏ Replace the property spring.datasource.data-username with spring.sql.init.username and update to the new credentials.

  • ❏ Remove the property spring.datasource.schema-username.

2. Provide a DataSourceInitializer bean

  • ❏ Add this bean definition to a bean configuration class (annotated with @Configuration).

@Bean
public DataSourceInitializer dataSourceInitializer() {
   // code with relevant information extracted from the application during scan...
   // ...
}
Tip

🤖 Can be automated 🤖

Apply the recipe boot-2.4-2.5-datasource-initializer.

2.5. Spring Data JPA

Spring Data JPA introduces a new getById method which replaces getOne.
If you find your application is now throwing a LazyLoadingException please rename any existing getById method to getXyzById (where xyz is an arbitrary string).
For more details, please read the updated Spring Data JPA reference documentation.

Relevance

The scan found calls to JpaRepository.getOne(id). This method was deprecated and JpaRepository.getById(id) should be used instead.
The scan also found getById(id) methods implemented by query derivation in JpaRepository implementations.
Please see the table below for more information of what needs to be changed.

File Description Proposed change

target/testcode/spring-boot-2.4-to-2.5-example/src/main/java/com/example/springboot24to25example/TaskRepository.java

defines getById(java.lang.Long) returning Task

Rename method to getTaskById()

target/testcode/spring-boot-2.4-to-2.5-example/src/main/java/com/example/springboot24to25example/TagService.java

calls org.springframework.data.jpa.repository.JpaRepository.getOne

replace with call to org.springframework.data.jpa.repository.JpaRepository.getById()

Todo

  • ❏ rename com.example.springboot24to25example.TaskRepository.getById(java.lang.Long) to getTaskById()

Tip

🤖 Can be automated 🤖

Apply the recipe boot-2.4-2.5-spring-data-jpa.