Card 03/ 07

ComparisonDifficulty: Intermediate1 min

@Component, @Service, @Repository, @Controller

All four mark a class for component scanning, and all four register a bean the same way. What differs is what each one communicates about the class's role — to a reader, and in one case, to the container itself.

The stereotype annotations
AnnotationSignalsMechanical difference from @Component
@ComponentA generic, container-managed classNone — it's the base annotation the other three build on
@ServiceBusiness logic, an application's use casesNone
@RepositoryData accessTranslates persistence-specific exceptions into Spring's own DataAccessException hierarchy
@ControllerA web layer handlerRecognized by Spring MVC for request mapping

So the decision rule is about honesty, not behaviour for three of the four: @Component still works everywhere, but @Service on a use case and @Repository on a data-access class tell the next reader what the class is for in a way @Component never does. @Repository's exception translation is the one row here where the choice changes what actually happens at runtime.