How to configure spring-boot to use file based H2 database

后端 未结 5 641
闹比i
闹比i 2020-12-23 10:51

I have successfully created a spring boot application that uses the H2 embedded database in-memory. I would now like to change this to a file based version that will persist

5条回答
  •  误落风尘
    2020-12-23 11:48

    Using the following setting on application.properties, I manage to keep the data persisted even after shutting down and restarting SpringBoot, and even after restarting the computer.

    spring.datasource.name=japodb
    spring.datasource.initialize=false
    spring.datasource.driverClassName=org.h2.Driver
    
    spring.datasource.url=jdbc:h2:file:~/japodb;DB_CLOSE_ON_EXIT=FALSE;IFEXISTS=TRUE;DB_CLOSE_DELAY=-1;
    

    Don't Close a Database when the VM Exits, yes, but also don’t make a new database if it’s already there.

    jdbc:h2:;IFEXISTS=TRUE
    
    spring.jpa.hibernate.ddl-auto = update
    

提交回复
热议问题