'spring.datasource.initialize is deprecated

I have a springboot application where I am trying to add following to application.properties file

spring.datasource.initialize=false

When I add this I see a warning as below:

enter image description here

I tried finding out what's the new property that replaces this deprecated property but in vain.

Can anybody help on this!

Having a reference to a migration guide would be great.



Solution 1:[1]

In Spring Boot 2.5, 'spring.datasource.initialization-mode' has been depracated as well: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.5-Release-Notes#SQL-Script-DataSource-Initialization

you should use:

spring.sql.init.mode=always  

or

spring.sql.init.mode=never  

You can read more at:
https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto.data-initialization

Solution 2:[2]

As per Spring Boot Migration mentioned in Github

Basic DataSource initialization is now only enabled for embedded data sources and will switch off as soon as you’re using a production database. The new spring.datasource.initialization-mode (replacing spring.datasource.initialize) offers more control.

spring.datasource.initialization-mode=always

Solution 3:[3]

You can use spring.jpa.defer-datasource-initialization. Refer to this Spring Documentation on how to Initialize a Database Using Basic SQL Scripts:

spring.jpa.defer-datasource-initialization=true

Solution 4:[4]

spring.sql.init.enabled=true - to initialize database by data.sql script located in application resources spring.sql.init.enabled=false - to

Solution 5:[5]

The property spring.datasource.initialization-mode from Spring boot verion 2.7 and onwards is not any more depracated. It has been completely removed!

So the change into the replacement property spring.sql.init.mode is a must do from now on.

Spring Boot 2.7 changelog

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Jaspreet Jolly
Solution 3 Subhrajit Sadhukhan
Solution 4 Krzysztof Smyk
Solution 5 Panagiotis Bougioukos