Spring boot doesn't load data to initialize database using data.sql

Try adding this line in application.properties:

spring.datasource.initialization-mode=always

There may be other causes, but this will certainly stop it running:

ddl-auto: validate

Hibernate will only execute data.sql for create or create-drop; change to

ddl-auto: create

or

ddl-auto: create-drop

Spring documentation on database initialization.

[EDIT] Hibernate WILL flatten your existing database with this setting - don't do this on production.


This works for me:

spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.initialization-mode=always

Please remember to not use 'create-drop' on production. It will drop your database after application stop.