Bird
0
0

Which annotation should you use to automatically register a class as a Spring Bean during component scanning?

easy📝 Conceptual Q2 of 15
Spring Boot - Inversion of Control and Dependency Injection
Which annotation should you use to automatically register a class as a Spring Bean during component scanning?
A@Bean
B@Component
C@Service
D@Configuration
Step-by-Step Solution
Solution:
  1. Step 1: Understand component scanning

    Spring scans for classes annotated with stereotypes to register them as Beans.
  2. Step 2: Identify the annotation for automatic detection

    @Component is the generic stereotype annotation for automatic detection and registration.
  3. Final Answer:

    @Component -> Option B
  4. Quick Check:

    @Component marks classes for auto-detection [OK]
Quick Trick: @Component enables automatic bean registration [OK]
Common Mistakes:
  • Using @Bean which is for method-level bean definitions
  • Confusing @Service as the only annotation for beans
  • Mistaking @Configuration as a bean marker

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes