O'Reilly logo

Spring: Developing Java Applications for the Enterprise by Ravi Kant Soni, Rajesh RV, Amuthan Ganeshan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dependency Injection

Dependency Injection (DI) is a design pattern in which an object's dependency is injected by the framework rather than by the object itself. It reduces coupling between multiple objects as it is dynamically injected by the framework. In DI, the framework is completely responsible for reading configuration.

The advantages of DI are as follows:

  • Loosely coupled architecture.
  • Separation of responsibility.
  • Configuration and code are separate.
  • A different implementation can be supplied using configuration without changing the code dependent.
  • Improves testability.
  • DI allows you to replace actual objects with mock objects. This improves testability by writing simple JUnit tests that use mock objects.

Dependency Injection in Spring

In the Spring ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required