Autowiring
Part of our application may use other parts, for example, a component uses another. If we look at our example, we can see that we created a service named ExampleService and that our Controller uses it as part of the constructor. When the component scan finds our controller, because is annotated with @Controller, it will discover that our class has a constructor that receives parameters.
The constructor parameter is a class that is already in the Spring context since it is as annotated with @Service, so the component scan will get the bean on the context and sends it as a parameter to the constructor of our controller. But sometimes, we may just have this as a parameter within our class, not as a parameter in the constructor, so ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access