Skip to main content
InterviewHubPRO
Section Overview
Q5

Question 5 of 50

Part 1: Spring Core, Auto-Configuration & Architecture (1 - 10)

10%
Spring Boot & Microservices (50 Qs)•Part 1: Spring Core, Auto-Configuration & Architecture (1 - 10)

What is the difference between `@Component`, `@Service`, `@Repository`, and `@Controller`?

senior LevelComponentsSystem Design

In Simple Words: All are Spring stereotype annotations that inherit from @Component for classpath scanning, but provide semantic clarity:

  • @Component: Generic Spring-managed component.
  • @Service: Marks business logic layer.
  • @Repository: Marks data access layer. Automatically enables database exception translation (PersistenceExceptionTranslationPostProcessor converts vendor SQL exceptions into Spring's DataAccessException hierarchy).
  • @Controller / @RestController: Marks HTTP web entrypoints. @RestController combines @Controller + @ResponseBody.