Mar*_*kus 7 spring h2 spring-data spring-boot
我正在尝试使用 Spring Boot 将 H2 内存数据库持久化到一个文件中,以重用其中的数据。
不幸的是,指定数据源 url 的方式如下
spring.datasource.url = jdbc:h2:file:~/WeatherDB;FILE_LOCK=FS
Run Code Online (Sandbox Code Playgroud)
对我不起作用。我在硬盘上的任何地方都找不到 H2 生成的文件(另外,重新启动服务器后保存的数据不可用)。
为了可视化这一点,我创建了一个示例项目,可以在Bitbucket上找到。
有了这个,如果应用程序是从 IDE 运行的,gradle run或者从 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"
}
},
Run Code Online (Sandbox Code Playgroud)
但是我WeatherDB在我的硬盘上找不到文件,重新启动服务器后也没有任何数据可用。
非常欢迎任何建议;-)
小智 11
由于架构迁移将表设置为更新而被删除,这为我解决了。
application.properties
spring.jpa.hibernate.ddl-auto=update
Run Code Online (Sandbox Code Playgroud)
您的application.properties文件未被获取。代替
compile "org.springframework.data:spring-data-jpa:1.7.2.RELEASE"
compile "org.hibernate:hibernate-entitymanager:4.3.8.Final"
Run Code Online (Sandbox Code Playgroud)
和
compile "org.springframework.boot:spring-boot-starter-data-jpa"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10210 次 |
| 最近记录: |