We need our data persistence with configuring our datasouce:
In application.properties:
spring.h2.console.enabled=truespring.h2.console.path=/h2spring.datasource.url=jdbc:h2:file:~/gs-spring-bootspring.datasource.username=saspring.datasource.password=spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.max-active=10 spring.datasource.max-idl=8 spring.datasource.max-wait=10000 spring.datasource.min-evictable-idle-time-millis=1000 spring.datasource.min-idle=8 spring.datasource.time-between-eviction-runs-millis=1
"
spring.datasource.url=jdbc:h2:file:~/gs-spring-boot
" tells to save the in memory data into a file called 'gs-spring-boot', you can name the file whatever you want.
Rebuild the application, login h2:
Make sure you change the JDBC URL. Now everytime you restart the server, data won't lost