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 (PersistenceExceptionTranslationPostProcessorconverts vendor SQL exceptions into Spring'sDataAccessExceptionhierarchy).@Controller/@RestController: Marks HTTP web entrypoints.@RestControllercombines@Controller+@ResponseBody.