Spring / Spring7 basics Interview questions
What are stereotype annotations in Spring?
Stereotype annotations are specialized forms of @Component that both register a class as a bean and communicate its architectural role to Spring and to other developers reading the code.
| Annotation | Role |
@Service | Business/service-layer logic |
@Repository | Data-access layer; enables automatic persistence exception translation |
@Controller / @RestController | Web layer handling HTTP requests |
Functionally, all of these behave like @Component for scanning purposes, but @Repository additionally activates Spring's PersistenceExceptionTranslationPostProcessor, converting low-level database exceptions into Spring's consistent DataAccessException hierarchy.
More Related questions...