Spring Boot Dependency Injection
Question Variations
- "Why is constructor injection preferred over field injection?"
- "How do you inject one of several implementations?"
- "When should a bean be request-scoped?"
Why This Is Asked
Dependency injection is central to Spring design. This question evaluates constructor injection, bean ownership, and how to resolve multiple implementations safely.
Key Concepts
- Constructor injection makes required dependencies explicit and testable.
- Components and
@Beanmethods define container-managed objects. @Primaryand@Qualifierdisambiguate multiple candidates.- Bean scope should match lifecycle and concurrency needs.
Question Variations
- “Why is constructor injection preferred over field injection?”
- “How do you inject one of several implementations?”
- “When should a bean be request-scoped?”