springboot2.0x 配置執行 schema.sql 指令碼
阿新 • • 發佈:2018-12-14
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