The main idea in Dependency Injection is that you don't have to create your objects but you just have to describe how they should be created.
The components and services need not be connected by us in the code directly. We have to describe which services are needed by which components in the configuration file. The IoC container present in Spring will wire them up together.
In Java, the 2 major ways of achieving dependency injection are:
Constructor injection: Here, IoC container invokes the class constructor with a number of arguments where each argument represents a dependency on the other class.
Setter injection: Here, the spring container calls the setter methods on the beans after invoking a no-argument static factory method or default constructor to instantiate the bean.