Dependency Injection (DI) in Spring

After getting an idea of how Spring manages bean life cycle, next we will learn how Spring provides and maintains the dependencies in your application.

DI is a process of providing the dependent objects to other objects that need it. In Spring, the container supplies the dependencies. The flow of creating and managing the dependencies is inverted from client to container. That is the reason we call it an IoC container.

A Spring IoC container uses the Dependency Injection (DI) mechanism to provide the dependency at runtime. In Chapter 1Why Dependency Injection?, we saw various DI types such as constructor, setter method, and interface-based. Let's see how we can implement the constructor and setter-based ...

Get Java 9 Dependency Injection now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.