Spring stereotype’s are annotations that denote the roles of types or methods in the overall architecture at a conceptual rather than implementation level according to the Spring Docs.
These stereotype’s help you mark different part of your spring application with the specific role they represent and can come with a lot of helper services, for example when you mark a class with @Repository and this class fulfils the stereotype then as part of the use case of this marker, you get automatic exceptions translation.
Below are some of the stereotype’s that spring supports
- @Component is a generic stereotype for any spring-managed component.
- @Repository is specialization of @Component, which should be used in the persistence layer.
- @Service is another specialization of @Component, which should be used in the service layer.
- @Controller is also a specialization of @Component, which should be used in the presentation layer.
@Component is a meta-annotation, which means that it can be applied to another annotation, e.g the service annotation is meta-annotated with @Component, what this means is that spring will treat the @Service in the same way it treats @component.
Component classes can be marked with @Component but using the right marker will make your classes suitable for processing by tools that are equipped to handle these markers and also there specialized markers might contain more semantics than their top counter part.
References : Spring Docs