JavaBeginner#spring

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

All are stereotype annotations registering a class as a Spring bean. @Service marks business logic, @Repository marks DAO/persistence layer classes (adds exception translation), @Controller marks MVC web controllers, and @Component is the generic base annotation.

Example
@Repository
class UserRepository {}
@Service
class UserService {}
@RestController
class UserController {}

Related Questions

1
JavaIntermediate#spring

What is Spring Boot auto-configuration?

Open
2
JavaIntermediate#spring

What is the purpose of @RestController vs @Controller in Spring MVC?

Open
3
JavaAdvanced#spring

What is Spring AOP and what is it used for?

Open