Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 582
Vinay Prajapati Avatar asked Mar 07 '19 09:03

Vinay Prajapati


People also ask

What is spring DataSource initialize?

82.3 Initialize a DatabaseSpring Boot can automatically create the schema (DDL scripts) of your DataSource and initialize it (DML scripts). It loads SQL from the standard root classpath locations: schema. sql and data. sql , respectively. In addition, Spring Boot processes the schema-${platform}.

What is SQL init mode always?

sql. init mode to always initialize the SQL database. It also enables the fail-fast feature by default for the script-based database initializer, i.e. the application cannot start if the scripts throw exceptions.

What is Spring JPA Hibernate DDL Auto?

spring. jpa. hibernate. ddl-auto (enum) is a Hibernate feature that controls the behavior in a more fine-grained way.


3 Answers

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

like image 189
Uri Loya Avatar answered Oct 16 '22 08:10

Uri Loya


As per the document

Spring Boot automatically creates the schema of an embedded DataSource. This behaviour can be customized by using the spring.datasource.initialization-mode property. For instance, if you want to always initialize the DataSource regardless of its type:

spring.datasource.initialization-mode=always

Look at this migration guide

like image 11
soorapadman Avatar answered Oct 16 '22 07:10

soorapadman


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
like image 3
Jaspreet Jolly Avatar answered Oct 16 '22 08:10

Jaspreet Jolly