Featured Article

Spring Boot H2 Database Tutorial: Master In-Memory Storage Fast

Kenneth Jul 13, 2026

Spring Boot, a powerful framework for building Java applications, seamlessly integrates with H2, an in-memory database, to provide a simple and fast database option for your projects. This tutorial will guide you through setting up H2 with Spring Boot and explore its key features.

Spring Boot H2 Database Example With Hibernate
Spring Boot H2 Database Example With Hibernate

By the end of this tutorial, you'll have a clear understanding of how to work with H2 in a Spring Boot application, helping you to streamline your development process and make the most of this lightweight database solution.

Spring Boot H2 Database
Spring Boot H2 Database

Setting up H2 with Spring Boot

To get started, let's first add the H2 dependencies to your Spring Boot project. If you're using Spring Boot's dependency management, you'll only need to add the runtime dependency:

#springboot #javadeveloper #backenddevelopment #softwarearchitecture #apis #microservices #systemdesign #cloudengineering #devops #programmingtips | Ignacio C.
#springboot #javadeveloper #backenddevelopment #softwarearchitecture #apis #microservices #systemdesign #cloudengineering #devops #programmingtips | Ignacio C.

Maven:

```xml com.h2database h2 runtime ```

Gradle (Kotlin):

HAL Browser and HATEOAS with Spring Boot Full Tutorial(Step by Step)
HAL Browser and HATEOAS with Spring Boot Full Tutorial(Step by Step)

```groovy runtimeOnly('com.h2database:h2') ```

Configuring H2 in application.properties

Now, let's configure H2 in your `application.properties` file. Add the following settings to enabling the console and file-based databases:

```properties spring.h2.console.enabled=true spring.h2.console.path=/h2-console spring.h2.console.settings.web-allow-others=true spring.datasource.url=jdbc:h2:file:./data/mydb;DB_CLOSE_DELAY=-1 spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password= spring.jpa.hibernate.ddl-auto=update ```

Here, we've configured H2 to create an in-memory database (`file:./data/mydb`) that persists data between restarts, and we've set Hibernate to update the schema based on our entities.

Discover H2 In-memory Database Magic in Spring Boot | Why H2 In-memory DB Stands Out
Discover H2 In-memory Database Magic in Spring Boot | Why H2 In-memory DB Stands Out

Accessing the H2 console

With the configuration in place, you can now access the H2 console by visiting in your browser. Log in with the credentials `SA` (without a password) to start interacting with your database.

You'll find the H2 console's interface simple yet effective, allowing you to run SQL queries, view tables, and even visualize data in a grid format.

Autowiring In Spring
Autowiring In Spring

Key Features of H2 with Spring Boot

Now that you've set up H2 with Spring Boot, let's explore some of its key features that make it an excellent choice for development environments:

Spring Core Tutorials
Spring Core Tutorials
Top 20 Spring Cloud Interview Questions and Answers for 3 to 5 Years Experienced [2025]
Top 20 Spring Cloud Interview Questions and Answers for 3 to 5 Years Experienced [2025]
Spring Boot Tutorial: Build an MVC Java Web App using Netbeans – Djamware
Spring Boot Tutorial: Build an MVC Java Web App using Netbeans – Djamware
the block diagram shows how to use an external memory for windows and mac osm
the block diagram shows how to use an external memory for windows and mac osm
Programming with Bee-Bot
Programming with Bee-Bot
What’s Boot from LAN / Network Booting & How to Boot from Network - MiniTool
What’s Boot from LAN / Network Booting & How to Boot from Network - MiniTool
Boot flow  |  Android Open Source Project
Boot flow  |  Android Open Source Project
Shoemaking School Pt. 9 — Boot patterns
Shoemaking School Pt. 9 — Boot patterns
the instructions for how to use an app
the instructions for how to use an app

In-memory database for fast performance

H2 stores data in memory, making it blazingly fast for development purposes. Since H2 is integrated into Spring Boot, your application will enjoy improved performance without any extra effort.

Schema migration and data generation

With tools like Lombok and Flyway, you can generate boilerplate code and manage database migrations with ease. By integrating these tools with Spring Boot and H2, you can maintain a clean and efficient project structure.

Automatic database configuration

Spring Boot provides automatic configuration for H2, making it a breeze to set up and manage an in-memory database. With just a few lines of configuration, you can have H2 up and running in your application.

As you've seen in this tutorial, Spring Boot simplifies working with H2 by providing automatic configuration and seamless integration. Embracing H2 for your development environment will greatly improve your productivity and help you focus on building innovative features for your applications.