springboot2.0x 執行schema.sql腳本注意要加上一個配置:spring.datasource.initialization-mode=always
表示始終執行初始化。
默認執行的sql腳本是在類路徑下,名爲schema.sql,要想修改,可以通過 spring.datasource.schema 指定。
例如:
sql腳本位置:
application.yml:
spring:
datasource:
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/springboot
schema:
- classpath:sql/department.sql
- classpath:sql/employee.sql
initialization-mode: ALWAYS
application.properties:
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/springboot
spring.datasource.schema=classpath:sql/department.sql,classpath:sql/employee.sql
spring.datasource.initialization-mode=always