Setting up a database connection

In every application, there is a need to access some data and conduct some operations on it. Most frequently, this source of data is a data store of some kind, namely a database. Spring Boot makes it very easy to get started in order to connect to the database and start consuming the data via the Java Persistence API among others.

Getting ready

In our previous example, we created the basic application that will execute a command-line runner by printing a message in the logs. Let's enhance this application by adding a connection to a database.

Earlier, we already added the necessary jdbc and data-jpa starters as well as an H2 database dependency to our build file. Now, we will configure an in-memory instance of the ...

Get Spring Boot Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.