根据文档 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/