Reputation: 4719
I have set up my Spring Boot application so that my H2 embedded database is populated at startup. I've done this by creating a data.sql file in the src/main/resources
folder.
What I don't understand is what causes this to run at startup.
Also, I'd like to make this conditional - e.g. prevent it from executing when I'm running unit tests. Is this possible?
A similar question was asked here, but it is unresolved.
Upvotes: 1
Views: 1405
Reputation: 937
The mechanism that causes your data.sql file to be loaded is described in the Spring documentation in chapter 85.3 Database Initialization
The data.sql file name is the fallback filename when no scripts are set through the property spring.datasource.data
(for a list of common spring properties go here and look for properties regarding datasource)
So for your usecase rename you dml scripts to something like data-default.sql
and data-test.sql
and set them profile specific in your application.yml or properties file.
Upvotes: 2