Junior — Middle
Can you name other annotations in Spring that are used to define components, besides @Bean and @Component?
sobes.tech AI
Answer from AI
In addition to @Bean and @Component, there are other annotations in Spring for defining and managing components:
- @Service — a specialized annotation for the service layer, semantically indicating that the class contains business logic.
- @Repository — for components that interact with the database; also helps Spring handle data access exceptions.
- @Controller — for defining controllers in MVC applications that handle HTTP requests.
- @RestController — combines @Controller and @ResponseBody, used for REST APIs.
All these annotations are specialized variants of @Component and help structure the application into layers.