Spring Boot Data Repository
Explore how to upgrade a Spring Boot application to use Spring Data JPA for dynamic database integration. Understand adding Maven dependencies, implementing entity classes, repositories, and modifying services to accommodate live data handling with H2 database.
In the previous chapter, we migrated our old school Billionaire’s Club application to leverage Spring Data JPA.
In this chapter, we will upgrade our Elite Club application to use Spring Ddata JPA.
Problem
Our first version of the Elite Club application works fine.
Now we are seeing recurring requests from customers to add and delete new clubs. Our existing design of the application is not adaptable enough to cater to such requirements. Because club lists are hardcoded in the service class, we’d have to redeploy our application every time there are new requests.
Let’s upgrade our application.
Solution
Yes, we can keep that information in DB. When requested, we can add a new entry to our table.
- We need to design a persistence layer. Let’s do it with Spring Data JPA.
Step1 - Add Maven dependency
As our application uses Spring Boot, why not use one of the starter libraries which enables Springdata? We need to add the below dependency in our Maven POM. . We need to add the below dependency in our maven pom.
<dependency>
...