IOC stands for the Inversion of Container. It is a container used in the Spring core Framework. It is responsible for managing the states of the object i.e from its creation till its destruction. Before Spring framework, developer/programmer was responsible for creating the object and destroying the object, but with the development of Core Spring it is taken care by its Container itself i.e IOC container, but programmer need to configure something in the XML file to indicate Container when and how to create an instance of the bean. In Spring a general java class i.e POJO ( Plain Old Java Object ) are considered as Bean. And its instance is called as Bean Object.
When to create a Bean object is defined by mapping bean in the XML. As it mapped in the XML, in that way Container tries to create its Object.
How to create a Bean Object is defined by Dependencies Injection.So Injection can be done in two ways only , either by Constructor or by Getter method. In general ways injection is defined as the way of creating an Bean class Object.
Three main responsibility of the IOC is
1. Loading the bean classes .
1. Creating an instance for the bean using Dependencies Injection
3. Injecting the bean dependencies.
Spring Container reads the Configuration metadata where we configured our bean classes with its Dependency Injection. Together using POJO classes and its configuration in the XML file , Container try to load the bean classes and Inject the bean dependencies.
In Spring There are two types of IOC container ,
1. BeanFactory Container.
2. ApplicationContext Container. ( Supports Annotation )
ApplicationContext was developed after BeanFactory with some extending functionality and over comes some of the limitations which was with the BeanFactory and introduce some of the new feature like supporting Annotation etc.
Note : A Container is simply a java object which manages the different states of an object and manages the life cycle of bean.
EmoticonEmoticon