JaiswalTraining

Get the online training



Corejava Servlet Jsp  Php  Hibernate  Ajax Web Service   Ejb2.1 Ejb3.0 Struts Struts2  JPA Spring Ibatis   JSF    JSF2.0  CoreJavaDesignPattern    Jquery  Flex J2EE-Design-Patterns  Jboss7  Maven  Contact Me                                                                                                                                                                        
            IGNOU SMU PTU Project                                           Training                                                                                                                              
              

Contact Us  0091- 9210721663         jaiswaltraining@gmail.com




Corejava
Servlet
Jsp
Php
Hibernate
Ajax
Web Service
Ejb2.1
Ejb3.0
Struts  
Struts2
JPA
Spring
Ibatis
JSF
JSF2.0
CoreJavaDesignPattern
Jquery
Flex
J2EE-Design-Patterns
Jboss7
Maven








Overview of Spring


What is Spring?

Spring is an open-source  and Lightweight framework created to address the complexity of enterprise application development.

  • Management of Objects within an Application.
  • Can  be Used with JEE and Java
  • Provide Spring Container
    • Application Context(In Web-Layer)
    • Bean Factory(In Stand-Alone)
  • Spring provides a light weight solution for building enterprise ready applications.
  • Spring can be used for both standalone application (Java SE )& web application (Java EE )
  • Spring is Open Source
  • Multi – tier Framework
Features

  • Management of Objects
  • Open Source
  • Promotes Dependency Injection
  • Promotes Loose Coupling
  • Lightweight & Non-intrusive

The Spring Framework contains a lot of features, which are well-organized in six modules




The Core package is the most fundamental part of the framework and provides the IoC and Dependency Injection features.

The Context package:-  it provides a way to access objects in a framework-style manner in a fashion somewhat reminiscent of a JNDI-registry.

The DAO package provides a JDBC-abstraction layer that removes the need to do tedious JDBC coding and parsing of database-vendor specific error codes. 

The ORM package provides integration layers for popular object-relational mapping APIs, including JPA, JDO, Hibernate, and iBatis. 

Spring's AOP package provides an AOP Alliance-compliant aspect-oriented programming implementation allowing you to define, for example, method-interceptors and pointcuts to cleanly decouple code implementing functionality that should logically speaking be separated. “Aspect Oriented Programming” refers to the ability to add side effects to a class’ method calls without modifying the class’ source code

Spring's Web package provides basic web-oriented integration features, such as multipart file-upload functionality, the initialization of the IoC container using servlet listeners and a web-oriented application context. 

Spring's MVC package provides a Model-View-Controller (MVC) implementation for web-applications.


Installation and Setup

Downloading

You can Download the Neccessory Spring Jar file from the following site

http://www.springsource.org/download

Spring With Eclipse

Example:- A simple example using eclipse IDE

  • click on New----->Project

 

  • Select Java Project


  • Give it  any name 
  • Here we are  giving it SpringJavaApplication



Adding Spring libraries
  • Then Right click on Project------->build  path--->configure build path
  • thern click on Add External jar
  • Add all necessory Spring jar files
  • click on ok.






  • Create a new class fie.
  • Name it as Message.java.




  • Add the package name as mypack.
  • Click on the finish button  as shown below.


  • Now add  the code as shown below.

Message.java

package mypack;

public class Message {

  

  public Message() {
  System.out.println("Object of Message created.");
  }
  

  public void display() {
    
    System.out.println("Welcome to Spring Java Example");
  }
}


  • Right click on src----------> New------>others


  • Select xml--->xml file
  • give it any name  Springconfiguration.xml




Springconfiguration.xml

<?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.xsd"
>

<bean id="mobj" class="mypack.Message">
  
</bean>

</beans>


Client file Creation

  • Now we will create another file to test the program
  • Create one java class file.
  • Name it as Client.java inside the package  mypack.
  • Now add the code as shown below.

Client.java

package mypack;
package mypack;

import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;

public class Client {
    private static XmlBeanFactory beanfactory;
    public static void main(String[] args) {
        Resource file = new FileSystemResource("src/Springconfiguration.xml");
        System.out.println("Spring Configuration File Found");
        beanfactory = new XmlBeanFactory(file);
        System.out.println("Bean factory created");

        Message message = (Message) beanfactory.getBean("mobj");
        message.display();
    }

}

}


  • Now we have all the required files in our project.
  • Fig below is showing the architecture of the project.
  • It is also showing the spring  jar files that has been set in the build path

Directory Structor will be




Run  the project
  • right click on project
  • click on run as------>Java Application



Output




Download Eclispe Zip Code