Spring IOC Hello World Example.

Today we will share a simple Spring 3 inversion of control hello world example program.

What is Inversion of Control (IOC) or Dependency Injection (DI)?

Inversion of control or dependency injection is an object oriented programming technique, in which the object coupling is done at runtime instead of compile time. The responsibility of creating, injecting and managing the life cycle of the object is inverted from programmer to framework.

Types of Dependency Injection.(DI)

  1. Constructor Injection.
  2. Setter Injection.
  3. Interface Injection.

For more details on inversion control and related patterns please refer to this post from Martin Fowler.

Java based IOC containers.

Name of container Interface injection Constructor injection Setter injection
Spring No Yes Yes
Pico No Yes Yes
Guice ? Yes Yes
XWork Yes ? ?
WebWork Yes ? ?

In the above listed containers Spring is the most commonly used DI framework. Google Guice is still in beta version.

Spring 3 IOC Hello World example program.

In this example we are using spring 3.2.3.RELEASE.

Maven repository for Spring 3.

Spring 3.2.3 Dependencies.

Spring 3 IOC example complete code.

Project structure.

Spring IOC Hello World Example Program

Download complete source code.

Please click here download the complete source code.

Leave a comment

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