1. Spring Boot SQL初始化
1.1 data.sql的加载
通过org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker(实现ApplicationEvent接口)注册事件,在applicationContext注册时会回调注册的事件(DataSourceInitializerInvoker的onApplicationEvent),来触发初始化data.sql.
通过org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer该类(createSchema方法用于执行schema.sql文件,initSchema()方法用于执行data.sql文件),查找SQL文件,并执行.
1.2 schema.sql的加载
在(spring-beans.*.jar)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory的:
invokeInitMethods方法中此时已经初始化完成了Bean,在此方法中回调org.springframework.beans.factory.InitializingBean接口(实际调用:org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker类)的afterPropertiesSet方法,
在DataSourceInitializerInvoker类的afterPropertiesSet方法中调用了org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer类的createSchema()方法,以执行schema.sql文件.
展开