According to this topic on stackoverflow, programmers (including me) often wonder about responsibilities of classes annotated with @Service and @Component. What we can find in Spring documentation:
@Componentis a generic stereotype for any Spring-managed component.
@Controllerare specializations of
@Componentfor more specific use cases
so, there isn’t any specific responsibility for @Component annotation in Spring – in my understanding.
If this isn’t specified – why not to create our own definition?
Let’s start: when we try to imagine @Component and @Service as a something touchable – what will be bigger?
right – @Component!
My definitions of @Service and @Component are:
@Service should be a class of service layer (service layer pattern). contain only @Repositories – for lower complexity,
@Component should be something like group for @Services. It should contains @Services, @Repositories or other @Components.
My definition of @Component is on the way with `composition over inheritance`.
There is also another advantage – but this will be mentioned in separate post.