使用 spring boot 导入数据 [英] Importing Data with spring boot
问题描述
我的 flyway 和 spring-boot 工作正常,但我似乎无法正确连接我的 spring.datasource.data
.
I have flyway and spring-boot working correctly, but I can't seem to wire up my spring.datasource.data
correctly.
如果我有一个文件 src/main/resources/db/seeds/one_project.sql
.我在 application.properties
文件中尝试了以下内容.
If I have a file src/main/resources/db/seeds/one_project.sql
. I have tried the following inside my application.properties
file.
# fully qualified path
spring.datasource.data=file:///fully/qualified/path/db/seeds/one_project.sql
# classpath specific
spring.datasource.data=classpath:/db/seeds/one_project.sql
# relative path
spring.datasource.data=/db/seeds/one_project.sql
我唯一能真正开始工作的是将 one_project.sql
复制到 src/main/resources/schema.sql
(甚至将它复制到 src/main/resources/data.sql
不起作用.
The only thing I can actually get to work is to copy one_project.sql
to src/main/resources/schema.sql
( even copying it to src/main/resources/data.sql
does not work.
文档中是否有我完全遗漏的内容?
Is there something I am completely missing from the documentation?
我一直在关注文档这里.
预先感谢您的帮助!
推荐答案
TL;DR
Create a blank schema.sql if you want your data.sql to run.
Also as stated in a comment it must execute one line such as `select 1` or `select 1 from dual`
你说
我唯一能真正开始工作的是将 one_project.sql 复制到 src/main/resources/schema.sql
The only thing I can actually get to work is to copy one_project.sql to src/main/resources/schema.sql
这让我觉得很明显你没有 schema.sql
Which makes me think it's evident you don't have a schema.sql
所以只需创建一个空白的 schema.sql 然后它就会运行 one_project.sql
So just create a blank schema.sql and then it will run one_project.sql
源代码-https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.爪哇
Source Code -https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java
如您所见,它收集架构位置,如果架构资源为空,则它不会继续运行 data.sql(这是在 runSchemaScripts() 方法的顶部)
As you can see it gathers the schema locations and if schema resources are empty then it doesn't continue to run the data.sql (this is at the top of the runSchemaScripts() method)
这篇关于使用 spring boot 导入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!