Bird
0
0

Which annotation is used to declare a class as a Spring Bean?

easy📝 Syntax Q12 of 15
Spring Boot - Inversion of Control and Dependency Injection
Which annotation is used to declare a class as a Spring Bean?
A@Qualifier
B@Component
C@Autowired
D@RequestMapping
Step-by-Step Solution
Solution:
  1. Step 1: Identify annotations for beans

    @Component marks a class as a Spring-managed bean.
  2. Step 2: Differentiate from other annotations

    @Qualifier specifies which bean to inject, @Autowired injects beans, @RequestMapping maps web requests.
  3. Final Answer:

    @Component -> Option B
  4. Quick Check:

    @Component = Bean declaration [OK]
Quick Trick: Use @Component to declare beans; others serve different roles [OK]
Common Mistakes:
  • Confusing @Autowired with bean declaration
  • Using @RequestMapping for beans
  • Thinking @Qualifier declares beans

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes