Skip to main content

Posts

Showing posts from March, 2013

Simple Spring Dependency Injection example

In this article I will show you a simple example for Spring Dependency Injection which is also known as Inversion Of Control (IoC). I am using Spring Tool Suite for this example even though STS is not mandatory for Spring development. According to Wikipedia " Dependency injection is a software design pattern that allows removing hard-coded dependencies and making it possible to change them, whether at run-time or compile-time.". I think this is a precise and well defined definition for dependency Injection design pattern. Now it is our turn to understand how this design patter works and how it help to achieve the goal of design patterns i.e Well defined solutions to commonly existing problems or scenarios. Lets start with an example, We have a Vehicle interface and 2 child classes Car and Truck. Both Car and Truck has 2 methods printModel() and testEngine() inherited. I have created a File-> New -> Spring Project named SpringDI.I have create