Suppose you are working on a project where you need to create several beans with business logic, database interaction, and APIs. How would you use different annotations to organize and define these beans properly?

  • @Component for beans, @Service for business logic, @Repository for database interaction, and @Controller for APIs.
  • @Bean for all types of beans.
  • @Entity for beans, @Data for business logic, @Service for database interaction, and @RestController for APIs.
  • @Resource for all types of beans.
In a Spring Boot project, it's essential to use the appropriate annotations for proper organization. Use @Component for general beans, @Service for business logic, @Repository for database interaction, and @Controller for APIs. This ensures that beans are correctly categorized, leading to better code organization and maintainability. The other options either do not follow the recommended Spring Boot annotation conventions or mix them inappropriately.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *