简体   繁体   中英

What Spring class is responsible for executing schema.sql?

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 is DataSourceInitializer#createSchema() .

Here are the high level flow which somehow triggers it:

  1. If DataSource class is found from the class-path, spring-boot auto-configuration will enable DataSourceAutoConfiguration
  2. DataSourceAutoConfiguration imports DataSourceInitializationConfiguration
  3. DataSourceInitializationConfiguration registers DataSourceInitializerPostProcessor which will be executed and force initialising DataSourceInitializerInvoker .
  4. DataSourceInitializerInvoker 's afterPropertiesSet will then execute DataSourceInitializer#createSchema() to read and execute schema.sql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM