Spring 引导 JPA 架构初始化

Spring Boot JPA Schema Initialization

我想在我的 spring 引导项目中使用 DLL 脚本初始化我的数据源(当然只在开发期间)。如文档 here 中所述,我将 spring.datasource.schema 属性 设置为 src/main/resources/postgresql/define-schema.sql.

中的 DLL 脚本
spring:
  profiles: dev
  datasource:
    platform: postgresql
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://localhost:5432/postgres
    username: postgres
    password: ****
    initialize: true
    schema: ./postgresql/define-schema.sql
    continue-on-error: false
  jpa:
    hibernate:
      ddl-auto: validate
      generate-ddl: false
      show-sql: true

但是脚本不会执行。我也试着把它放在 class 路径根目录下,并称它为 schema.sql ... 没有任何反应。

选择了dev配置文件,至少我在日志中看到了:The following profiles are active: dev 应用程序在 JPA 模式验证时失败。

我从休眠中得到的唯一警告: Found use of deprecated [org.hibernate.id.SequenceGenerator] sequence-based id generator; use org.hibernate.id.enhanced.SequenceStyleGenerator instead. See Hibernate Domain Model Mapping Guide for details. 但我认为这与初始化问题没有任何关系。

我的依赖项中有 spring-boot-security-starter 但尚未配置,这可能是问题来源吗?

有没有人认出一个明显的打字错误,还有其他错误吗?

期待您的回音!

安培

在 sql 脚本的路径前加上 classpath

示例:

spring.datasource.schema=classpath:/postgresql/define-schema.sql