Bean declaration
First of all, let's take a look at how to use Spring annotations to declare beans.
Spring provides a set of stereotype annotations for declaring beans, including @Component, @Service, @Controller, and @Repository. We can apply these annotations to the classes that need to be managed by Spring. And Spring will pick them up by scanning the packages, starting from the base package that we provide to the @ComponentScan annotation.
The @Component annotation is a generic stereotype. When a class is annotated with this annotation, Spring will instantiate an instance of that class. The @Service annotation is a specialization of @Component, and it indicates that the annotated class is a service, a term used in Domain-Driven Design ...
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