Springboot数据库初始化
据我从 Spring Reference 文档中了解到,我们可以使用 data.sql 和 schema.sql 文件来初始化数据库。
当应用程序的多个实例针对单个数据库运行时,如何使 data.sql
和 schema.sql
文件仅运行一次,而不是在所有数据库中执行容器。
As I understand from Spring Reference
docs, we can use the data.sql
and schema.sql
files for initializing the database.
When there are multiple instances of the application running against a single database, how to make the data.sql
and schema.sql
files run only once and instead of executing in all the containers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要禁用默认的 spring 数据初始化。您可以通过
While Spring 的属性文件来执行此操作,网址为 9.如果您希望基于脚本的
DataSource
初始化能够建立在由 < code>Hibernate,设置为 true,这将推迟数据源初始化,直到创建并初始化任何
EntityManagerFactory
beans 之后。为了跨多个应用程序实例管理数据库,您可以使用
Flyway
和Liquibase
,使用基本的schema.sql
和data.sql 不建议将
脚本与Flyway
或Liquibase
一起使用,并且将在未来版本中删除支持。You need to disable the default spring data initialization. You can do this through your properties file by
While Spring at 9. Database Initialization does not recommend using multiple data source initialization technologies, if you want script-based
DataSource
initialization to be able to build upon the schema creation performed byHibernate
, setTo true, this will defer data source initialization until after any
EntityManagerFactory
beans have been created and initialized.And for managing your database across multiple application instance you can use
Flyway
andLiquibase
, sing the basicschema.sql
anddata.sql
scripts alongsideFlyway
orLiquibase
is not recommended and support will be removed in a future release.