Spring Tutorials

Spring Tutorial

Introduction of Spring Framework

Advantages and Disadvantages of Spring Framework

Features of Spring Framework

Basic concept of Spring Framework

Architecture of Spring Framework

Modules of Spring Framework

Goal of Spring Framework

Create Application of Spring without any IDE

Create Application of Spring in Eclipse IDE

Create Application of Spring in MYEclipse IDE

Important JAR of Spring Framework

IOC container in Spring Framework

Bean and Applicationcontext container in Spring Framework

Example of Spring BeanFactory Container in Spring Framework

Example of Spring ApplicationContext Container in Spring Framework

Bean in Spring Framework

Lifecycle of Bean in Spring Framework

Scope of Bean in Spring Framework

Autowiring in Spring Framework

Dependency Injection in Spring Framework

Constructor-based Dependency Injection Example in Spring Framework

Setter-based Dependency Injection Example in Spring Framework

Introduction of AOP in Spring Framework

Core concept and Goal of AOP in Spring Framework

AOP Proxies in Spring framework

XML Schema Based AOP in Spring Framework

AOP Xml based Configuration Example in Spring Framework

Example of Declaring AOP Advices in Spring Framework

AOP AspectJ Annotation with Example in Spring Framework

Declaring an aspect and pointcut using Annotation in Spring Framework

Declaring AOP Advices using Annotation Example in Spring Framework

DAO support in Spring Framework

Introduction of Spring JDBC Framework in Spring Framework

Introduction of Spring JdbcTemplate in Spring Framework

Example of Spring JdbcTemplate class in Spring framework

Example of Executing SQL statements in Spring Framework

Example of Executing DDL statements in Spring Framework

SQL Stored Procedure in Spring Framework

Example of NamedParameterJdbcTemplate in Spring Framework

Example of RowMapperJdbcTemplate in Spring Framework

Introduction of ORM Framework in Spring Framework

Integration of Spring with Hibernate in Spring Framework

Integration of Spring with JPA in Spring Framework

Introduction of Spring Expression Language (SpEL) in Spring Framework

Example of Spring Expression Language (SpEL) in Spring framework

Example of Spring EL in XML and Annotation in Spring Framework

Language Reference with SpEL in Spring Framework

Operators in Spring Expression Language(SpEL) in Spring Framework

Variable in Spring Expression Language(SpEL) in Spring Framework

Introduction of Spring Framework Transaction Management in Spring Framework

Spring Framework Transaction Abstraction

Spring Declarative Transaction Management in Spring Framework

Spring Programmatic Transaction Management in Spring Framework

Introduction of Spring OXM (Object XML Mapping) in Spring Framework

Integration of Spring with Jaxb Example in Spring framework

Example of Spring with Xstream in Spring Framework

Example of Spring with Castor in Spring Framework

Remote Method Invocation(RMI) in Spring Framework

Spring and RMI Integration with Example in Spring Framework

Example of Spring and Httpinvoker in Spring Framework

Example of Spring and Hessian in Spring Framework

Integration of Spring with JMS in Spring Framework

Introduction of Webservice in Spring Framework

Spring Web Services in Spring Framework

Web Services with Jax-WS in Spring framework

Exposing and Exporting servlet-based Web Services using JAX-WS in Spring Framework

Accessing Web Services using JAX-WS in Spring Framework

Introduction of JMS in Spring Framework

JMS Messaging Models in Spring Framework

Using Spring JMS in Spring Framework

Sending and Receiving a Message Using JMS API in Spring Framework

Introduction of JMX (Java Management Extension) in Spring Framework

Integrating Beans with JMX in Spring Framework

Creating a MBeanServer in Spring Framework

Introduction Java Mail with Spring in Spring Framework

Example of Java Mail with spring in Spring Framework

Introduction of EJB(Enterprise JavaBeans) in Spring Framework

Introduction of EJB(Enterprise JavaBeans) Integration in Spring Framework

Integration of Spring With Struts 2 Example in Spring Framework

Spring MVC

Spring MVC

adplus-dvertising
Example of Spring Application in MYEclipse IDE
Previous Home Next

There are following some steps to create Spring application in MYEclipse as given below.

Setup Java Development Kit (JDK)

Step1. First You can download the latest version of JDK from Oracle's Java site, You will find instructions for installing JDK in downloaded files, follow the given instructions to install and configure the setup. Finally set PATH and JAVA_HOME environment variables on your System.

Download MYEclipse IDE

Step2. Now you can download the latest version of MYEclipse IDE below link.

Create Java Project

Step3. Now you create a simple Java Project using MYEclipse IDE. Follow the option File -> New -> Project and finally select Java Project wizard from the wizard list. Now name your project as FirstSpringApplication using the wizard window.

Add spring jar files

Step4. Go to Myeclipse menu - Project Capabilities - Add spring capabilities - Finish. Now the spring jar files will be added. For the application we need only core library i.e. selected by default.

Create Java class file

Step5. Now you create simply java file with any name. First we need to create a package with any name like com.r4r. To do this, Right click on src in package explorer section and follow the option : New -> Package. and then Right click on package(com.r4r) - New - class - Write the class name e.g. Employee - finish. Write the following code:

package com.r4r;
public class Employee {
private String name;//variable declaration.
private int age;
public String getName() {  //getter and setter.
    return name;  
}  
public void setName(String name) {  
    this.name = name;  
}  
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
} 
 public void print(){  //This is a metod.
    System.out.println("Name: "+name);  
    System.out.println("Age: "+age); 
}
}

Employee is simple bean class, containing only two property name and age with its getters and setters method. This class contains one extra method named print() that prints the employee name and age. The name and age of the employee will be provided by the xml file.

Create XML file

Step6. When you used MYEclipse IDE, you don't need to create the xml file as MYEclipse does this automatically. Open the applicationContext.xml file, and write the following code.

<?xml version="1.0" encoding="UTF-8"?>  
<beans  
    xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:p="http://www.springframework.org/schema/p"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">  
<bean id="emp" class="com.r4r.Employee">  
<property name="name" value="John Smith"></property>  
<property name="age" value="25"></property> 
</bean>  
</beans>  

The bean element is used to define the bean for the given class. The property subelement of bean specifies the property of the Employee class named name and age. The value specified in the property element will be set in the Employee class object by the IOC container.

Create the Demo class

Step7.Now Create the java Test class, Here we are getting the object of Employee class from the IOC container using the getBean() method of BeanFactory.

package com.r4r;
import org.springframework.beans.factory.BeanFactory;  
import org.springframework.beans.factory.xml.XmlBeanFactory;  
import org.springframework.core.io.ClassPathResource;  
import org.springframework.core.io.Resource;  
public class Demo {
public static void main(String[] args) {  
Resource resource=new ClassPathResource("applicationContext.xml");  
BeanFactory factory=new XmlBeanFactory(resource);  
Employee employee=(Employee)factory.getBean("emp");  
employee.print();  
}  
}  

Here Resource object represents the information of applicationContext.xml file. The Resource is the interface and the ClassPathResource is the implementation class of the Reource interface. The BeanFactory is responsible to return the bean. The XmlBeanFactory is the implementation class of the BeanFactory. There are many methods in the BeanFactory interface. One method is getBean(), which returns the object of the associated class.

Run Application

Now run the Application you see the following output

Name: John Smith
Age: 25
Previous Home Next