Software Development, Linux, and Windows

Notes on Software Development, Linux, and Windows

Configure SpringBoot with H2 Database

Prerequisite:

Go to start.spring.io and create a new SpringBoot project with Web, H2, and DevTools for dependencies.

Import new project into STS (Spring Tools Suite).

Additions to application.properties:

Open /src/main/resources/application.properties and add the following lines:


# H2
spring.h2.console.enabled=true
spring.h2.console.path=/h2
# Datasource
spring.datasource.url=jdbc:h2:file:~/test
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver

spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.show-sql=true

NOTE: If you want your database schema to be automatically created automatically from your entity definitions for development or demo purposes then use one of the following:

  • spring.jpa.hibernate.ddl-auto=create
  • spring.jpa.hibernate.ddl-auto=create-drop

Exercise caution in using this, and for more information see spring.jpa.hibernate.ddl-auto options