juniorSpring
Difference between @Component, @Service, and @Repository
Updated May 17, 2026
Short answer
@Component is generic, @Service is for business logic, @Repository is for persistence layer.
Deep explanation
All three are stereotype annotations. @Repository adds exception translation, @Service improves readability, and @Component is generic fallback.
Real-world example
Separating layers in a banking application for clarity and maintainability.
Common mistakes
- Using @Component everywhere instead of meaningful stereotypes.
Follow-up questions
- Does @Service add behavior?
- What does @Repository add?