Spring 3 IoC Container Overview

In this tutorial we will check the overview of Spring IoC Container. Interface org.springframework.context.ApplicationContext represents the Spring IoC container and is responsible for instantiating, configuring, and assembling the beans. But how and from where container gets information like which Object to Instaniate, how to configure and assemble it.

Configuration metadata required for container can be provided in any of three ways.

  1. XML
  2. Java Code
  3. Java Annotations

Spring IoC container takes a form of configuration metadata(Which explain container how to initiate object and configure) and combine it with application classes which in the end produces fully configured system.

Spring IoC container is totally decoupled from the type in which metadata configuration is written(e.g. Java based, java annotation or XML).

Java Based metadata configuration Example(Since Spring 3.0)


Annnotation Based Configuration Metadata Example(Since Spring 2.5)


XML Based Configuration Metadata Example

Instantiating IoC Container

ApplicationContext constructor requires string(configuration metadata).  Constructor will be used to instantiate the IoC container.

contact.xml will contain configuration metadata as mentioned above.

ApplicationContext constructor loads bean definition from different XML configuration file. Different XML configuration file can be imported in a single XML file as below.

As mentioned above, external bean definitions are loaded from contact.xml.

Once configured as above, configured bean instance can be retrieved in below mentioned way.


1 Comment Spring 3 IoC Container Overview

Leave A Comment

Your email address will not be published. Required fields are marked *