I am making my own ORM and I'm at the point where I need to push the SQL code I've generated from my entity classes to the database. I do not aim to copy how Spring does it but rather see what phase of the lifecycle it runs in and how exactly.
Thanks
The actual class that read schema.sql
and execute it used to be DataSourceInitializer#createSchema()
. As of Spring Boot 3.3, it is in SettingsCreator
.
Here are the high level flow which somehow triggers it :
DataSource
class is found from the class-path , spring-boot auto-configuration will enable DataSourceAutoConfiguration
DataSourceAutoConfiguration
imports DataSourceInitializationConfiguration
DataSourceInitializationConfiguration
registers DataSourceInitializerPostProcessor
which will be executed and force initialising DataSourceInitializerInvoker
.DataSourceInitializerInvoker
's afterPropertiesSet
will then execute DataSourceInitializer#createSchema()
to read and execute schema.sql