I'm trying to persist an H2 in-memory DB to a file with Spring Boot to reuse the data in there.
Unfortunately, the way to specify the datasource url like
spring.datasource.url = jdbc:h2:file:~/WeatherDB;FILE_LOCK=FS
(complete application.properties)
doesn't work for me. I can't find a file generated by H2 anywhere on my hard disk (also, saved data is not available after restarting the server).
To visualize this, I created a sample project that can be found on Bitbucket.
With that, it doesn't seem to make a difference if the application is run from an IDE with gradle run or after packaging it from the jar.
What config option is needed to persist and reuse the H2 DB ?
Update:
I realized there is a actuator endpoint for config options at http://localhost:8080/configprops that shows
"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"
}
},
But I just can't find an file WeatherDB on my harddisk nor is any data available after restarting the server.
Any suggestions very much welcome ;-)