Skip to content
Sharp

Dependency Injection · interview question

Why can using field injection with private fields in a Spring Boot application become a problem in practice?

Multiple choiceEasychapter-9-curatedpremiumdependency-injectionconstructor-vs-field-injection
Choose one answer
Answer and explanation

Correct answer

A. Makes the class difficult to unit test

Why

Field injection with private fields makes the class difficult to unit test because dependencies cannot be easily mocked or swapped. Constructor injection facilitates testability by allowing dependencies to be injected at the time of object creation.

Test yourself on Dependency Injection

A free test with instant, explained results. No account needed.

Start free test
All Dependency Injection questions →