From the course: Creating Spring Boot Microservices
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Spring Data JPA repository dependency injection - Spring Boot Tutorial
From the course: Creating Spring Boot Microservices
Spring Data JPA repository dependency injection
- [Instructor] So now, let's inject the repositories into Spring bean services. In the exercise files, I have a new folder called business, and we're going to have our business logic and two services, TourPackageService and TourService. So TourPackageService, I've annotated this as a Spring bean with the @ annotation and remember auto wiring, it will auto wire the tour package repository 'cause it will recognize that the tour package repository automatically is a Spring bean. You don't need to annotate it with repository, it's known by Spring Data JPA. It's going to put it into the constructor, and now let's populate this createTourPackage method to actually invoke our tour package repository. So we're going to say tourPackageRepository.findById, because we want to look up to see if this tour package exists already, and if it does, then we'll return it, otherwise we'll create a new one. So let me have that auto complete happen again, findById, find it by the code orElse, leveraging…
Contents
-
-
-
-
-
(Locked)
The domain model2m 9s
-
(Locked)
The persistence entities2m 2s
-
(Locked)
Declare JPA repositories4m 36s
-
(Locked)
Spring Data JPA repository dependency injection3m 48s
-
(Locked)
Invoking the repositories7m 33s
-
(Locked)
Introduction to Spring Data query methods3m 2s
-
(Locked)
Challenge: Create a JPQL query method38s
-
(Locked)
Solution: Create a JPQL query method2m 35s
-
(Locked)
-
-
-
-
-
-
-