Spring Boot : H2 database not saved to file

标签 spring spring-boot spring-data h2

我正在尝试使用 Spring Boot 将 H2 内存数据库持久化到一个文件中,以重用其中的数据。

不幸的是,指定数据源 url 的方式如下

spring.datasource.url = jdbc:h2:file:~/WeatherDB;FILE_LOCK=FS

( complete application.properties )

对我不起作用。我在我的硬盘上的任何地方都找不到 H2 生成的文件(另外,重新启动服务器后保存的数据不可用)。

为了可视化这一点,我创建了一个示例项目,可以在 Bitbucket 上找到。 .

有了这个,如果应用程序从带有 gradle run 的 IDE 运行似乎没有什么区别。或从 jar 中包装后。

需要什么配置选项来持久化和重用 H2 DB?

更新:

我意识到在 http://localhost:8080/configprops 处有一个用于配置选项的执行器端点这表明
"spring.datasource.CONFIGURATION_PROPERTIES": {

    "prefix": "spring.datasource",
    "properties": {
        "schema": null,
        "data": null,
        "xa": {
            "dataSourceClassName": null,
            "properties": { }
        },
        "separator": ";",
        "url": "jdbc:h2:file:~/WeatherDB",
        "platform": "all",
        "continueOnError": false,
        "jndiName": null,
        "sqlScriptEncoding": null,
        "password": "******",
        "driverClassName": "org.h2.Driver",
        "initialize": true,
        "username": "sa"
    }
},

但我就是找不到文件 WeatherDB重新启动服务器后,我的硬盘上也没有任何数据可用。

非常欢迎任何建议;-)

最佳答案

由于架构迁移将表设置为更新而被删除,这为我解决了。

application.properties
spring.jpa.hibernate.ddl-auto=update

关于 Spring Boot : H2 database not saved to file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28921896/

相关文章:

java - 回调是什么意思?

java - 没有 ehcache.xml 的 Hibernate 二级缓存

Spring Boot @Value 属性

java - 将 map 转换为 HStore

java - 如何在 Spring 数据中获取嵌套对象的大小

spring - 使用 Spring 限制 findAll 可能?

java - spring 中的 org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException

java - 同时在服务器上上传多个视频

java - 自定义过滤器突然破坏@WebMvcTest

java - 从 JPA 实体自动生成 Spring Data Repositories