【问题标题】:Spring Boot JPA bootstrapping the databaseSpring Boot JPA 引导数据库
【发布时间】:2017-08-22 03:54:00
【问题描述】:

当使用 Spring Boot JPA (Hibernate) 时,使用一些种子数据(在本例中为 MySQL)引导数据库的最佳方法是什么?例如,在 Grails 中,您可以使用 bootstrap.groovy 文件来完成此操作。对于最佳实践中的最佳解决方法,我无法达成真正的共识。

【问题讨论】:

    标签: spring hibernate grails spring-boot spring-data-jpa


    【解决方案1】:

    您可以使用LiquibaseFlyway 方法。

    或以下Spring Boot 属性:

    spring.datasource.data= # Data (DML) script resource references.

    spring.datasource.schema= # Schema (DDL) script resource references.

    另一种解决方案是创建自己的 Bootstrap bean 并在应用启动之前运行它,看看 Spring Boot 如何运行 FlywayLiquibase 作为参考。

    Database initialization documentation

    【讨论】:

      【解决方案2】:

      您可以简单地在resources 文件夹中创建一个文件,将其命名为schema.sql,然后将您的 MySQL 数据库脚本放入其中。当您的应用程序启动时,schema.sql 将自动加载

      【讨论】:

        猜你喜欢
        • 2014-10-21
        • 2021-05-04
        • 2022-01-11
        • 2017-02-20
        • 2020-02-08
        • 2017-11-06
        • 1970-01-01
        • 2016-02-28
        • 1970-01-01
        相关资源
        最近更新 更多