Spring H2嵌入数据库文件? [英] Spring H2 embedded-database file?

查看:846
本文介绍了Spring H2嵌入数据库文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用嵌入式jetty和H2数据库在maven上运行我的petproject:

I currently run my petproject on maven using an embedded jetty and H2 database:

<jdbc:embedded-database id="dataSource" type="H2">
   <jdbc:script location="/WEB-INF/database.sql"/>
</jdbc:embedded-database>

此设置会在每次运行服务器时重置我的数据库。我想将数据库保存为磁盘中的文件,以便在每次启动服务器时不会丢失数据。

This setup resets my DB every time I run the server. I want to save the DB as a file in disk so that I do not lose my data upon every server start. How do I accomplish this?

推荐答案

您可以通过连接字符串来控制。

You can controll this by the connection string.

jdbc:h2:~/test; # saves to the file ~/test
jdbc:h2:mem:db1 # in memory

更多信息此处

编辑:

看起来像连接字符串 hard编码在春天H2配置中,所以我假设这意味着你有通过扩展编写自己的实现EmbeddedDatabaseConfigurer ,假设在 H2EmbeddedDatabaseConfigurer 中设置后,没有其他方法更改连接字符串。

Seems like the connection string is hard-coded in the spring H2 Configuration, so I assume that means you have to write you own implementation by extending the EmbeddedDatabaseConfigurer, assuming there is no other way of changing the connection string after it's set in the H2EmbeddedDatabaseConfigurer.

这篇关于Spring H2嵌入数据库文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆