Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

Spring Framework FAQ: Top Questions

8. What is the use of @Component, @Controller, @Service, and @Repository in Spring?

These annotations are used to mark classes as Spring-managed components with semantic meaning for different application layers.

📘 Roles:

  • @Component: Generic stereotype for any Spring-managed component.
  • @Controller: Marks a web controller for Spring MVC.
  • @Service: Denotes business logic/service classes.
  • @Repository: For DAO/persistence layer and exception translation.

🏆 Expected Output:

Classes are auto-detected and registered as beans.

🛠️ Use Cases:

  • Organizing application layers clearly.
  • Support for stereotype-based component scanning.