DEV Community

Saravanan B
Saravanan B

Posted on • Updated on

Spring 5 - Inversion of control.

IOC is a design principle which maintains the object creation and management.

Normally if we create a object for class it will stick to the particular class. In case of Inversion of control, we need to create object as per business requirement so we have to create new object everytime for the required object to overcome this Interface is used to solve tight coupling.

Image description

Image description

Image description

Image description

This will overcome the tight coupling still the code is not configurable.

Spring Container
create and manage the object(IOC)
Inject dependencies(DI).

There are 3 ways to configure spring container.
XML based (legacy)
Java Annotation
Java Source code

Steps :
Configuring spring bean
create a spring container
Retrieve beans from container.

XML Based

Image description

A "Spring Bean" is simply a Java object.

When Java objects are created by the Spring Container, then Spring refers to them as "Spring Beans".

Spring Beans are created from normal Java classes .... just like Java objects.

Now it will create a TrackCoach bean we dont need to change code in Java files.

Image description

Now it will create a bean for baseBallCoach

Image description

Top comments (0)