“Spring.sql.init.data-locations 中 DML 失效”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) |
Jihongchang(讨论 | 贡献) |
||
第28行: | 第28行: | ||
这是因为 <code>spring.sql.init.schema-locations</code> 和 <code>spring.sql.init.data-locations</code> 是在 Spring Boot 2.5.0 之后才有的 | 这是因为 <code>spring.sql.init.schema-locations</code> 和 <code>spring.sql.init.data-locations</code> 是在 Spring Boot 2.5.0 之后才有的 | ||
− | + | 如果确认当前用的是 Spring Boot 2.5.0 之前的版本就使用 <code>spring.datasource.schema</code> 和 <code>spring.datasource.data</code> 来配置数据库初始化。https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.5-Release-Notes#sql-script-datasource-initialization | |
− | |||
− | |||
− |
2023年2月16日 (四) 05:39的版本
以
# DataSource Config
spring:
datasource:
url: jdbc:h2:mem:testdb
driver-class-name: org.h2.Driver
schema: classpath:db/schema-h2.sql
username: root
password: test
hikari:
leak-detection-threshold: 2000
register-mbeans: true
sql:
init:
schema-locations: classpath:db/schema-h2.sql
data-locations: classpath:db/data-h2.sql
h2:
console:
enabled: true
path: /h2-console
settings:
trace: true
jpa:
show-sql: true
为例,启动之后发现 db/data-h2.sql 里 insert 的数据不存在
这是因为 spring.sql.init.schema-locations
和 spring.sql.init.data-locations
是在 Spring Boot 2.5.0 之后才有的
如果确认当前用的是 Spring Boot 2.5.0 之前的版本就使用 spring.datasource.schema
和 spring.datasource.data
来配置数据库初始化。https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.5-Release-Notes#sql-script-datasource-initialization