Sunday, December 8, 2013

About Spring

1.   Spring Introduction

Spring is created by Rod Johnson.Spring framework is developed to simplify the developed of enterprise applications in Java technologies. It is an open source framework begins developed by Spring Source Company. Spring framework is also available for .NET framework (Spring .NET).
The spring is light weight, non-invasive IoC Container and AOP framework. It provides support for JPA, Hibernate, Web services, Schedulers, Ajax, Struts, JSF and many other frameworks. The Spring MVC components can be used to develop MVC based web applications. Spring framework provides many features that make the development of enterprise application easy work.




2. Why We Need SPRING ? 


ü  Spring is a light weight and open source framework created by Rod Johnson in 2003. 
ü  Spring is a complete and a modular framework, can be used for all layer implementations for a real time application or spring can be used for the development of particular layer of a real time application unlike struts [ only for front end related ] and hibernate [ only for database related ], but with spring we can develop all layers.
ü  Spring framework is said to be a non-invasive means it doesn’t force a programmer to extend or implement their class from any predefined class or interface given by Spring API, in struts we used to extend Action Class right that’s why struts is said to be invasive
ü  Spring is light weight framework because of its POJO model
ü  Spring Framework made J2EE application development little easier, by introducing POJO model
ü  Simplicity : Actually for writing the spring application, server [Container] is not mandatory.
ü  Testability
ü  Loose Coupling
ü  Provides:
v  IOC
v  MVC
v  AOP
v  Transaction Management
v  Container Based i.e. Spring contains and manages the life-cycle and configuration of Application object.
v  Security Management
v  Internationalization
v  Integration with other tools and frameworks like Struts, Hibernate etc...
v  JDBC Exception Handling




3.   Spring Architecture


Spring is well-organized architecture consisting  of seven modules. Modules in the Spring framework are:
1.     Spring AOP
One of the key components of Spring is the AOP framework. AOP is used in Spring:
·    To provide declarative enterprise services, especially as a replacement for EJB declarative services. The most important such service is declarative transaction management, which builds on Spring's transaction abstraction.
·    To allow users to implement custom aspects, complementing their use of OOP with AOP

2.     Spring ORM
The ORM package is related to the database access. It provides integration layers for popular object-relational mapping APIs, including JDO, Hibernate and iBatis.
  
3.     Spring Web
The Spring Web module is part of Springs web application development stack,
which includes Spring MVC.
 
4.     Spring DAO
The DAO (Data Access Object) support in Spring is primarily for standardizing the data access work using the technologies like JDBC, Hibernate or JDO.
 
5.     Spring Context
This package builds on the beans package to add support for message sources and for the Observer design pattern, and the ability for application objects to obtain resources using a consistent API.
  
6.     Spring Web MVC
This is the Module which provides the MVC implementations for the web applications.
  
7.     Spring Core
The Core package is the most import component of the Spring Framework. Th
 
This component provides the Dependency Injection features. The Bean Factory provides a factory pattern which separates the dependencies like initialization, creation and access of the objects from your actual program logic


The following diagram represents the Spring Framework Architecture




4. Example Of Spring



i. POJO Class


public class FirstSpringClass {
 private String name;
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public void displayInfo() {
  System.out.println("Hello: " + name);
 }
}

 


























ii. Spring Configuration File


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean id="firstSpringExample" class="com.spring.examples.FirstSpringClass">
<property name="name" value="Sam This is my first Spring Example.." />
</bean>
</beans>

 





























iii. Util Class



package com.spring.examples;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringExample {
 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
  FirstSpringClass firstExample = (FirstSpringClass) ctx.getBean("firstSpringExample");
        firstExample.displayInfo();
 }
}

 














Next Page >Environment Set Up


No comments:

Post a Comment