Spring / Spring7 basics Interview questions
What is Dependency Injection in Spring?
Dependency Injection (DI) is the specific technique Spring uses to implement IoC: rather than a bean looking up or constructing the objects it needs, the container "injects" those dependencies into it, usually through a constructor, a setter, or a field.
For example, an OrderService that needs a PaymentGateway simply declares a constructor parameter of that type; Spring resolves a matching bean and passes it in automatically. This keeps classes free of wiring logic and lookup code, so the service never calls new StripeGateway() directly - it just asks for a PaymentGateway and trusts the container to supply one, which makes swapping implementations or mocking dependencies in tests straightforward.
More Related questions...