Spring Boot Interview Question

What is the difference between Component, Service, and Repository annotations?

Updated 2026-07-10 · Beginner friendly
Quick answer

All three mark a class as a Spring bean, and Service and Repository are actually specialisations of Component. Component is the generic marker. Service marks a class holding business logic. Repository marks a class handling data access and also translates database exceptions. They are functionally similar but express intent for different layers.

What each signals

@Service
class UserService { }

@Repository
class UserRepository { }

Repository adds one real behaviour beyond a label: it converts low level database exceptions into Spring's consistent DataAccessException, which makes error handling cleaner.

In the interview

Say they are all Component under the hood, but you use the specific ones to show which layer a class belongs to and to keep code readable. Mentioning Repository's exception translation is the detail that stands out.

Want the full Spring Boot guide?

Read every Spring Boot concept with notes, diagrams, and code in one place. Track your progress as you go.

Open the Spring Boot guide All Spring Boot questions