database - 将初始数据导入到 Spring Boot 应用程序中

标签 database hibernate spring-boot import spring-data-jpa

根据文档 http://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html要在启动时导入数据,您可以在 application.properties 中定义这两个属性:

spring.datasource.data=data.sql
spring.datasource.schema=schema.sql

当您拥有这两个文件但我没有架构时,这才有效。我正在使用 hibernate 生成数据库架构

spring.jpa.hibernate.ddl-auto=create-drop

之前的解决方法 Importing Data with spring boot是为 schema.sql 定义空白文件,但它不再起作用了。我会收到异常,文件不能为空白或 null

在 Spring 应用程序中我简单地定义了

<jdbc:initialize-database data-source="simpleDataSource">
    <jdbc:script location="classpath:dbscripts/data.sql"/>
</jdbc:initialize-database>

并且成功了。

有没有办法在 springBoot 中也有相同的行为?

最佳答案

只需删除 schema.sql + 配置选项,Spring Boot 就会自动仅选择 sata.sql

关于database - 将初始数据导入到 Spring Boot 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40991530/

相关文章:

jquery - 在spring中使用jquery表单发布到DB

java - Hibernate重复类名异常

java - 使用 hibernate 进行条件 AND

java - Hibernate InheritanceType.JOINED 阻止表创建

java - 如何使用 Spring Boot 在 REST Web 服务中的 POST 请求期间修复 'HTTP-415' 错误

java - 我如何转换字符串以将其实现为数据库字段 - Java/Spring/Postgres?

mysql - 什么是在数据库中创建图像文档存档的最佳方法?

python - 在 SQLAlchemy 中映射大量相似的表

java - 在oracle中使用long或Long映射 "NUMBER"列?

c++ - MySQL select for update,多线程超时