0

I am curious about the dependency injection process in Spring, moreover I want to know what actually happens behind the scenes while the spring injects the dependency, how does he do it?

UddeshyaSeth
  • 38
  • 1
  • 5
  • Does this answer your question? [What is Dependency Injection and Inversion of Control in Spring Framework?](https://stackoverflow.com/questions/9403155/what-is-dependency-injection-and-inversion-of-control-in-spring-framework) – pringi Feb 23 '22 at 09:18
  • No, I want the internal working – UddeshyaSeth Feb 23 '22 at 13:26

1 Answers1

0

Dependency Injection behind the scene

Suppose there are two classes vehicle and engine.So vehicle have engine. When we try to create an object of vehicle, we must have to create object of engine because of the dependency.

In Spring boot when we run application it will create the beans and put inside the spring container.

@Autowired annotation is used for DI (dependency Injection).

Spring Container will look inside the container , object of given type which is Autowired (example->engine).

like-> @Autowired engine Engine;

it will inject the object from spring container into the engine type;

This is know as Dependency Injection. IOC is the end product of DI.

Procrastinator
  • 2,526
  • 30
  • 27
  • 36