Complete the code to define a service class in Spring Boot.
@[1] public class UserService { // service methods }
The @Service annotation marks the class as a service layer component in Spring Boot.
Complete the code to inject the repository into the service class.
@Service public class UserService { private final UserRepository userRepository; public UserService([1] userRepository) { this.userRepository = userRepository; } }
The constructor parameter must be the repository type to inject it into the service.
Fix the error in the service method that calls the repository.
public List<User> getAllUsers() {
return userRepository.[1]();
}The correct repository method to get all records is findAll().
Fill both blanks to create a service method that saves a user entity.
public User [1](User user) { return userRepository.[2](user); }
The service method name can be saveUser, and the repository method to save is save.
Fill all three blanks to create a service method that deletes a user by id.
public void [1](Long [2]) { userRepository.[3]([2]); }
The service method is named deleteUserById, the parameter is id, and the repository method to delete by id is deleteById.