在SpringBoot1.x中, 通过schema执行sql语句,只需要命名文件为schema.sql或者schema-all.sql,放在resource下,或者只在yml的配置文件中配置sql语句的路径即可执行:
schema:
- classpath:sql/name.sql
- classpath:sql/age.sql
但是在springBoot2.x中这样配置,sql语句执行并不成功,这是因为在springboot2.x中需要对其添加另外一项配置
spring.datasource.initialization-mode: always
application.yml:
spring:
datasource:
url: jdbc:mysql://localhost:3306/user_db?serverTimezone=UTC
username: root
password: 1234
driver-class-name: com.mysql.cj.jdbc.Driver
# 表示始终执行初始化。
initialization-mode: always
schema:
- classpath:department.sql