How to connect to H2 Console in Spring Boot

In order to enable H2 In-Memory Database in Spring Boot applications you have to include the “h2” dependency in your initializer. For example:

spring init -dweb,jpa,h2 demo-h2

The H2 Database provides a web interface called H2 Console to see the data. You can enable the h2 console in the src/main/resources/application.properties

# Enabling H2 Console spring.h2.console.enabled=true 

You can launch up H2 Console at the following address: http://localhost:8080/h2-console

As far as H2 is concerned, as soon as Spring Boot sees H2 in the class path, it auto configures a data source similar to what you see below:

spring.datasource.url=jdbc:h2:mem:testdb spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password= spring.jpa.database-platform=org.hibernate.dialect.H2Dialect 

Found the article helpful? if so please follow us on Socials
Twitter Icon       Facebook Icon       LinkedIn Icon       Mastodon Icon