What is IoC or Spring IOC?

There is a lot of confusion about the definition of the IoC container – some equate it with a design pattern called Dependency Injection – but in reality IoC is much larger than dependency injection.

Inversion of Control (IoC) is an object-oriented programming practice where the object coupling is bound at run time by an assembler object and is typically not known at compile time using static analysis.

The basic concept of the Inversion of Control pattern (also known as dependency injection) is that you do not create your objects but describe how they should be created. You don’t directly connect your components and services together in code but describe which services are needed by which components in a configuration file. A container (in the case of the Spring framework, the IOC container) is then responsible for hooking it all up.

Steps to use the inversion of control (IOC) with spring framework.

=> Create one .xml file to configure the components and services.

=> We need to define classes and its properties.

=> Mention the service with its component as per springs framework
guidelines so that Spring container can create a object for us.



package com.techartifact.vinay;

public class RefClass {

                private RefClass newRefClass;

                public RefClass getRefClass() {

                                return newRefClass;


                public void setNewRefClass(RefClass newRefClass) {

                                this.newRefClass = newRefClass;



Configuration file

 <bean id="createRefClass" class="com.techartifact.vinay.RefClass">

        <property name="newRefClass"/>


Here RefClass is a class which has getter and setter for newRefClass property.

Now spring container takes the responsibility to create the object of RefClass class with object name newRefClass which defined in the property tag with name attribute and set the value automatically when it is used.

Bhupendra Pratap Singh

Having 4+ years of experience in java technology. Worked with various java and J2EE technology like jsp,servlet,struts,spring,ajax, web services,jquery. Hand on experience in BI with QlikView tool.If you wanna give feedback or something contact on [email protected]

More Posts - Website