How to configure h2 database in spring boot

  • Post author:
  • Post category:Java / Spring Boot
  • Post comments:0 Comments
  • Post last modified:May 16, 2022
  • Reading time:2 mins read

Hello, Today we will discuss how to configure the h2 database in the spring boot application properly.

Follow the below configuration of the H2 Database: add the properties in your application.properties file

spring.datasource.url=jdbc:h2:mem:testdb;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=
spring.datasource.password=
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
hibernate.dialect=org.hibernate.dialect.H2Dialect

testdb is the database name, you can change what you like…

And finally, we have to enable the console to use the UI of the H2 Database. So, add the line to the configuration file.

spring.h2.console.enabled=true

Visit your h2 database console by

http://localhost:8080/h2-console

All are done! Hope it helps!

Leave a Reply