About NewTechnoBuzz
Contact Us

Wednesday, July 9, 2014

Spring Inversion of Control(IOC) Overview

The Spring IOC container is at the core of the Spring Framework. The container creates the objects, wire them together, configure them, and manage their complete lifecycle from creation to destruction. The Spring container uses dependency injection (DI) to manage the components in an application. So, What is Dependency Injection (DI)?

The container gets instructions on what objects to instantiate, configure, and assemble by reading configuration metadata. The configuration metadata can be represented either by XML, Java annotations, or Java code. The Spring IoC container makes use of Java POJO classes and configuration metadata to produce a fully configured and executable system or application.

The following diagram is a high-level view of how Spring works.

Here, a question arises, what aspect of control are inverting?
Martin Fowler posed this question about Inversion of Control (IoC) on his site in 2004. Fowler suggested renaming the principle to make it more self-explanatory and came up with Dependency Injection.

For insight, refer to Fowler's article at http://martinfowler.com/articles/injection.html.

Free Search Engine Submission

Spring provides following two distinct types of containers.

  • BeanFactory
    This is the simplest container which provides basic support for dependency injection (DI) and is defined by the org.springframework.beans.factory.BeanFactory interface. The BeanFactory and its related interfaces, such as BeanFactoryAware, InitializingBean, DisposableBean are still present in Spring for the purposes of backward compatibility with the large number of third-party frameworks that integrate with Spring.
  • ApplicationContext
    This container adds more enterprise-specific functionality such as the ability to resolve textual messages from a properties file and the ability to publish application events to interested event listeners. This container is defined by the org.springframework.context.ApplicationContext interface.

Note: The ApplicationContext container includes all functionality of the BeanFactory container, so it is generally recommended over the BeanFactory. BeanFactory can still be used for light weight applications like mobile devices or applet based applications where data volume and speed is significant.

Configuration Metadata

The different forms of configuration metadata for Spring container are:

I hope this article helped you to understand. Please feel free to post any comment or question.