Bird
0
0

In Spring Boot, what is the primary role of a class annotated with @Component?

easy📝 Conceptual Q1 of 15
Spring Boot - Inversion of Control and Dependency Injection
In Spring Boot, what is the primary role of a class annotated with @Component?
AIt marks the class as a candidate for auto-detection and dependency injection.
BIt configures the class as a REST controller.
CIt disables component scanning for the class.
DIt automatically creates a database table for the class.
Step-by-Step Solution
Solution:
  1. Step 1: Understand @Component

    The @Component annotation indicates that the class is a Spring-managed bean.
  2. Step 2: Role in Spring Boot

    Spring Boot scans for classes annotated with @Component to register them as beans for dependency injection.
  3. Final Answer:

    It marks the class as a candidate for auto-detection and dependency injection. -> Option A
  4. Quick Check:

    Does @Component register the class as a bean? Yes [OK]
Quick Trick: @Component marks classes for Spring bean detection [OK]
Common Mistakes:
  • Confusing @Component with @Controller or @Service
  • Assuming @Component disables scanning
  • Thinking @Component creates database tables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes