From the course: Creating Your First Spring Boot Microservice

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Spring Data JPA repository dependency injection

Spring Data JPA repository dependency injection

From the course: Creating Your First Spring Boot Microservice

Start my 1-month free trial

Spring Data JPA repository dependency injection

- So now, let's inject the repositories into services. In the exercise files there is a new service folder and within that service folder there are two classes; TourPackageService and TourService, so let's look at TourPackageService. In here we have inject, the repository and then auto-wire to the constructor and we have three methods here. One is to create a TourPackage, one is to look up all of the TourPackages, and the final one is to get the total number of TourPackages. And the methods are stubbed out so we're actually going to put the implementation of them right now. So, we don't want to create a TourPackage for a given code or name if that already exists. So first we're going to look it up by the ID which is the code, and if it does not find it then we're going to create it and return the newly created one. If it does find it then we'll just return what's already exist in the database. So I'm going to make a change…

Contents