From the course: Spring Boot 3 Essential Training

Unlock this course with a free trial

Join today to access over 24,300 courses taught by industry experts.

Extracting a service layer

Extracting a service layer

- [Instructor] In the interest of not repeating ourselves, we're going to do a little bit of refactoring of our code in a common way and that is to build a service or business service layer between our data access and our view. So what I want you to do is to open up room web app, source, main, Java, and we'll create a package underneath our default package. And we will call this service. Now in here we will create a new Java class and we will call this room service. Now we're going to annotate this with @Service, which is a stereotype of @Component. That way we can auto wire it. And in order for this to work, we are going to need a private final room repository and we will inject that via the constructor. Now we're going to create a few methods. So let's start with the first one, which is going to be public list of our rooms. And this is from the web package, get all rooms, and we're not going to get to implementing these yet. Let's go ahead and define the interface. So we will do a…

Contents