intermediateSpring Boot Fundamentals303 of 469
What is Dependency Injection? Explain IoC, the types of DI, and constructor vs field injection (which is preferred and why).
Tests whether you argue for constructor injection -- it makes dependencies explicit and immutable (final fields), fails fast at startup if a dependency is missing, and makes the class testable without reflection, unlike field injection which hides the dependency graph and requires a DI framework even for unit tests.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a responseNext Step
←PreviousContinue to Why can returning a new object from a custom BeanPostProcessor silently remove @Transactional, @Cacheable, and @Secured proxies?→
← Back to all Spring Boot & Microservices questions