springboot2.0x 【schema.sql运行不生效解决方案】

在SpringBoot1.x中, 运行schema.sql不需要配置便可之间运行,但是在SpringBoot2.x中,、需要在yaml文件中配置
spring.datasource.initialization-mode: always

 

默认执行的sql脚本是在类路径下,名为schema.sql,要想修改,可以通过 spring.datasource.schema 指定。

例如:

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

 

 

posted @ 2020-02-07 10:50  李jojo  阅读(3525)  评论(0)    收藏  举报