here is an explanation why we need such specialization ...
In Spring 2.0 and later, the @Repository annotation is a marker for any class that plays the role or stereotype of a repository (also known as a data access object or DAO). Among the uses of this token are automatic exception translation.
Spring 2.5 introduces additional annotations to stereotypes: @Component, @Service and @Controller. @Component is a common stereotype for any Spring component. @Repository, @Service and @Controller are specializations of @Component for more specific use cases, for example, in persistence, service, and presentation levels, respectively.
That way, you can annotate your component classes with @Component, but instead annotate them with @Repository, @Service or @Controller, your classes are more suitable for tooling or aspect binding. For example, these stereotype annotations make ideal targets for pointcuts.
Thus, if you choose between @Component or @Service for your service level, @Service is definitely the best choice. Similarly, as stated above, @Repository is already supported as a marker for automatically converting exceptions at your persistence level.
Mayur gupta
source share