Spring Framework Introduction

Spring is a light weight and open source framework created by Rod Johnson in 2003.

Spring Framework made J2EE application development little easier, by introducing POJO model

Advantage of Spring


  • Spring is combination of technologies
  • The main feature of Spring is dependencies injection which helps you keep interface and implementation separate.
  • Aspect oriented programming, which isolates cross cutting concerns into modules that you can apply declaratively.
  • libraries to help with common tasks like persistence (JDBC, Hibernate, iBatis, JDO, JPA, etc.), remoting (RMI, HTTP, web services),asynch messaging (message driven POJOs), validating and binding, web MVC (Spring or Struts), utilities like e-mail, scheduling, security, etc
  • Spring’s application context is really just a big Factory Pattern.

Spring became more popular because of
— Loose Coupling
— Simplicity
— Testability

Dependency Injection


We use Dependency Injection (DI) to implement loose coupling.
The choice of any particulary DI Container is not that important.

Every time you create an instance of a class by using the new keyword,
you tightly couple your code to that class
,
and you will not be able to substitute that particularl implementation
with a different one (at least not without recompiling the code).

Let’s Understand it With Example.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
package com.spy;
 
public class Company 
{
 
	Employee emp;
 
	public Company() 
	{	
		emp=new Employee();
	}
 
}

In Above code Company and Employee object is tightly coupled with each other.


There is a Design Pattern which Helps you to make your code loosely coupled. i.e Factory Design Pattern.

1
2
3
4
5
6
7
8
9
10
11
12
 
public class Company 
{
 
	Employee emp;
 
	public Company(Employee emp) 
	{	
		this.emp=emp;
	}
 
}

Now Employee and Company object is loosely coupled with Each other.
Again some one has to pass Employee object.
So Spring inject this dependencies based on xml configuration.we will
understand it with Example.

Reference link:

Loose coupling

Leave a Reply

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