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