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

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM