【发布时间】:2019-07-10 07:04:01
【问题描述】:
我已经浏览了链接:https://walkingtechie.blogspot.com/2018/12/execute-schema-and-data-sql-on-startup-spring-boot.html 和 Spring Boot - Loading Initial Data,但仍然难以理解一些事情。
我希望在 Spring Boot 应用程序 运行开始时执行 schema.sql,因为我使用以下配置。我希望在 Postgres DB 上执行所有操作。
我在 sql/schema.sql 文件夹中创建了 schema.sql 文件。我希望 Spring Boot 能够拾取该文件并运行它。如果我们能做到,有什么办法吗?我正在使用Spring Boot 版本2.1.6.RELEASE 和Postgres 11.0。
spring:
datasource:
url: jdbc:postgresql://localhost:5432/test?currentSchema=test
username: postgres
password: postgres
platform: postgres
schema:
- classpath:sql/schema.sql
jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
default_schema: test
format_sql: true
jdbc:
lob:
non_contextual_creation: true
show-sql: true
hibernate:
ddl-auto: none
【问题讨论】:
标签: postgresql spring-boot initialization