Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Integrate an H2 Database in Your Spring Boot App

DZone's Guide to

Integrate an H2 Database in Your Spring Boot App

You have created a Spring Boot application and would like to integrate with an H2 database. What do you do?

· Integration Zone
Free Resource

Learn how API management supports better integration in Achieving Enterprise Agility with Microservices and API Management, brought to you in partnership with 3scale

In this tutorial, we will be integrating the H2 database in your Spring Boot application. Note that the H2 database is in the embedded mode.

You have created a Spring Boot application and would like to integrate with an H2 database.

In pom.xml, add the below dependency:

 <!-- H2 Database -->
 <dependency>
 <groupId>com.h2database</groupId>
 <artifactId>h2</artifactId>
 </dependency>

In the application.properties file, add the below line to enable the H2 database:

# 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

Take a Maven build and run the application as a Spring Boot app.

Open a browser and type http://localhost:8080/h2 to get the below image.

h2databasejosepraveen

The yellow highlighted lines should match your application.properties file.

h2databasejosepraveen1

That's it! If you get stuck, kindly comment below.

Unleash the power of your APIs with future-proof API management - Create your account and start your free trial today, brought to you in partnership with 3scale.

Topics:
spring boot ,integration ,h2 ,tutorial

Published at DZone with permission of Jose Praveen T. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}