Skip to content
Sharp

Dependency Injection · interview question

What issue might arise with field injection using @Autowired on private fields in a Spring Boot application?

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

Correct answer

D. Dependencies may not be initialized before use.

Why

Field injection can lead to a situation where the injected dependencies are not fully initialized before being used, as the injection happens after the constructor has run, potentially leading to NullPointerExceptions.

Test yourself on Dependency Injection

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

Start free test
All Dependency Injection questions →