Bird
0
0

What is a likely consequence of manually creating a Spring-managed bean instance instead of letting the IoC container manage it?

medium📝 component behavior Q5 of 15
Spring Boot - Inversion of Control and Dependency Injection
What is a likely consequence of manually creating a Spring-managed bean instance instead of letting the IoC container manage it?
AThe bean will be automatically registered and managed by Spring anyway
BThe manually created instance will not have its dependencies injected by Spring
CSpring will throw a compile-time error preventing manual instantiation
DThe application will run faster due to reduced overhead
Step-by-Step Solution
Solution:
  1. Step 1: Understand IoC container role

    Spring manages lifecycle and dependency injection of beans it creates.
  2. Step 2: Effect of manual instantiation

    Manually created instances are outside Spring's control and won't have dependencies injected.
  3. Final Answer:

    The manually created instance will not have its dependencies injected by Spring -> Option B
  4. Quick Check:

    Only Spring-created beans get dependency injection [OK]
Quick Trick: Manual instantiation bypasses Spring's injection [OK]
Common Mistakes:
  • Believing Spring manages all instances regardless of creation method
  • Expecting compile-time errors for manual instantiation
  • Assuming manual instantiation improves performance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes