1. Introduction
Datetime |
{{CREATION_DATE}} |
---|---|
Project dir |
|
Revision |
|
Project name |
spring-boot-2.4-to-2.5-example |
Coordinate |
|
Boot version |
|
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.
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) |
---|---|---|
|
|
|
|
|
|
Todo
-
❏ Replace the old property names to the new names in the given files.
Tip
|
🤖 Can be automated 🤖 Apply the recipe |
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
ornever
,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 |
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 |
Rename method to |
target/testcode/spring-boot-2.4-to-2.5-example/src/main/java/com/example/springboot24to25example/TagService.java |
calls |
replace with call to |
Todo
-
❏ rename
com.example.springboot24to25example.TaskRepository.getById(java.lang.Long)
togetTaskById()
Tip
|
🤖 Can be automated 🤖 Apply the recipe |