What are Spring stereotype annotations?

Why Interviewers Ask This

This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Spring Boot topics. It also reveals how well you can explain technical ideas to non-experts.

Answer

Spring stereotype annotations mark classes for component scanning and indicate their role in the application: @Component: generic Spring-managed component. Base annotation; use when no more specific annotation applies: utility classes, helpers. @Service: marks a service layer class — business logic, use cases. Functionally identical to @Component, but semantically indicates service layer. @Repository: marks a data access layer class. In addition to component behavior, adds PersistenceExceptionTranslation — converts JDBC/JPA exceptions to Spring's DataAccessException hierarchy for consistent error handling. @Controller: marks an MVC controller that handles HTTP requests and returns view names (for template engines). @RestController: @Controller + @ResponseBody — returns data (JSON) directly. @Configuration: marks a class as a bean definition source. Methods annotated with @Bean in this class create Spring beans. @ControllerAdvice / @RestControllerAdvice: applies to all controllers — global exception handling (@ExceptionHandler), model attributes. Component scanning: @SpringBootApplication (via @ComponentScan) automatically discovers all annotated classes in the main class's package and sub-packages. Custom stereotypes: create your own by annotating an annotation with @Component: @Component @Target(TYPE) @Retention(RUNTIME) public @interface Facade {}. Naming: Spring uses lowercase class name as bean name by default (UserService → userService). Customize: @Service("myUserService").

Pro Tip

If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.