Javatpoint Logo
Javatpoint Logo

Spring Boot JPA

Spring Boot provides spring-boot-starter-data-jpa starter to connect Spring application with relational database efficiently. You can use it into project POM (Project Object Model) file.

Here, we are creating a spring-boot application which uses JPA to connect to the database.

Spring Boot provides default server and apache derby database. So, we will use that in our application.

Now, let's create project. Follow the following steps.

Select project type

Spring Boot jpa 1

Provide project name.

Spring Boot jpa 2

Select dependencies

Spring Boot jpa 3

After finishing, create the following files.

// pom.xml






Our project looks like the following.

Spring Boot jpa 4

Now, run the application.

Spring Boot jpa 5

Here, we are using Postman plug-in of the Firefox browser to test our application. Postman is a nice tool which provides interface to request HttpRequests. You can download it from the official site of Firefox.

Opening Postman

Providing URL on which application is running. After that selecting HttpRequest method.

Spring Boot jpa 6

Submit the request.

After submitting, it returns a blank array as response because initially there is no data into the database.

Spring Boot jpa 7

Adding data into the repository.

Providing a new URL for adding user and data to insert. Select POST method and submit.

Spring Boot jpa 8

After submitting, it returns response code 200 which means data has inserted successfully.

Now, fetch the inserted record by changing the request URL.

Notice that after submitting, it returns inserted data in response box.

Spring Boot jpa 9

Well, we have created Spring Boot application by using JPA successfully.

Next TopicSpring Boot JDBC

Please Share

facebook twitter google plus pinterest tumbler

Learn Latest Tutorials