Bird
0
0

In Spring Boot, what is a primary drawback of using field injection with @Autowired?

easy📝 Conceptual Q1 of 15
Spring Boot - Inversion of Control and Dependency Injection
In Spring Boot, what is a primary drawback of using field injection with @Autowired?
AIt makes unit testing harder due to hidden dependencies
BIt improves code readability by reducing constructor code
CIt enforces immutability of dependencies
DIt automatically validates dependencies at compile time
Step-by-Step Solution
Solution:
  1. Step 1: Understand field injection

    Field injection uses @Autowired directly on fields, hiding dependencies from constructors.
  2. Step 2: Impact on testing

    Hidden dependencies make it difficult to create mocks or stubs for unit tests, reducing testability.
  3. Final Answer:

    It makes unit testing harder due to hidden dependencies -> Option A
  4. Quick Check:

    Hidden dependencies reduce testability [OK]
Quick Trick: Hidden dependencies reduce testability [OK]
Common Mistakes:
  • Assuming field injection improves readability
  • Believing field injection enforces immutability
  • Thinking field injection validates dependencies at compile time

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes