Sobes.tech
Junior — Middle

What annotations are used in Spring to define and manage components?

sobes.tech AI

Answer from AI

In Spring, the following main annotations are used for defining and managing components:

  • @Component — the basic annotation to denote a component that will be managed by the Spring container.
  • @Service — a specialized component, usually for business logic.
  • @Repository — for components that work with the database; also provides exception handling.
  • @Controller — for components that handle HTTP requests in MVC.
  • @RestController — combines @Controller and @ResponseBody, used for REST APIs.

For dependency management, the following are used:

  • @Autowired — for automatic dependency injection.
  • @Qualifier — to specify which bean to inject when there are multiple.

These annotations allow Spring to automatically scan, create, and inject necessary objects, simplifying application configuration.

What annotations are used in Spring to define and… - sobes.tech