Spring: @Component, @Service, @Repository and @Controller are all beans

They differ in intent, not in wiring. @Repository additionally translates persistence exceptions.

Code
@Component   // generic - anything Spring should manage
@Service     // business logic
@Repository  // data access + exception translation
@Controller  // web layer, returns view names
@RestController // @Controller + @ResponseBody

@Repository
public class JdbcOrderRepository {
    // SQLException is translated to DataAccessException here
}
Output
All four register a bean.
Only @Repository wraps vendor SQL exceptions in Spring's DataAccessException hierarchy.
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11