Answer the question
In order to leave comments, you need to log in
How does the relationship between classes work in a Spring Boot Application?
Please explain how the relationship between the classes in the example is organized. Why are the methods written in the BookServiceImpl class, which implements the BookService interface, executed, because only the interface is connected from the BooksController, and not its implementation. What happens if there are several options for implementing the BookService interface?
@RestController
@RequestMapping(value = "/books")
public class BooksController {
@Autowired
private BookService bookService;
}
public interface BookService {
}
@Service
public class BookServiceImpl implements BookService {
}
Answer the question
In order to leave comments, you need to log in
The @Service annotation tells Spring to create an instance of this class and put it in the application context.
The @Autowired annotation indicates that the dependency should be injected into the generated instance of the class. The appropriate dependency is selected by ID, name, or class (or its parent) of the injected dependency.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question