H2 Database Setup for Spring Boot

1. Add H2 Dependency

Add this to your pom.xml:

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <scope>runtime</scope>
</dependency>

2. Configure application.properties

# H2 Console Configuration
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console

# H2 Database Connection
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=admin_viewer
spring.datasource.password=password

# JPA/Hibernate Settings
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true

3. Access H2 Console

After running your application, access the console at:

<http://localhost:8080/h2-console>

Login credentials:


Quick Notes: