Can @Component, @Repository and @Service annotations be used interchangeably in Spring or do they provide any particular functionality besides acting as a notation device?>
We can answer this according to java standard
Referring to JSR-330
, which is now supported by spring, you can only use @Named
to define a bean (Somehow @Named=@Component
). So according to this standard, there seems that there is no use to define stereotypes (like @Repository
, @Service
, @Controller
) to categories beans.
But spring user these different annotations in different for the specific use, for example:
aspect-oriented
, these can be a good candidate for pointcuts
)@Repository
annotation will add some functionality to your bean (some automatic exception translation to your bean persistence layer).@RequestMapping
can only be added to classes which are annotated by @Controller
.