Deploy a Spring Boot App with H2 Database on AWS

Viewed 729

I want to deploy my Java Web Application with an internal H2 database on AWS. I creates application-prod.properties like:

server.port=5000
spring.datasource.url=jdbc:h2:./src/main/resources/data/demo
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.h2.console.settings.trace=false
spring.h2.console.settings.web-allow-others=false
spring.h2.console.settings.trace=false
spring.jpa.hibernate.ddl-auto=none

I package my application as jar and load it up to elastic beanstack. But when I deploy, the database always disappear and I need to recreate the whole schema. I just want to use the internal h2 database for my sample application and I want to keep the data in the database file. Does anybody know how I can achieve this? My application is a spring boot application based on vaadin.

Thanks and kind regards,

Nullpointer

1 Answers
/src/main/resources/data/demo 

probably does not exist on AWS because this is the directory on your local machine and you are deploying a JAR file.

Try to point to the user home like this:

spring.datasource.url=jdbc:h2:~/demo

But be aware that if BeansTalk will recreate the application the data may be lost.

Related