Here, we are going to create a simple application of spring framework using eclipse IDE. Let's see the simple steps to create the spring application in Eclipse IDE.
Create the java project
Add spring jar files
Create the class
Create the xml file to provide the values
Create the test class
Steps to create spring application in Eclipse IDE
Let's see the 5 steps to create the first spring application using eclipse IDE.
1) Create the Java Project
Go to File menu - New - project - Java Project. Write the project name e.g. firstspring - Finish. Now the java project is created.
2) Add spring jar files
There are mainly three jar files required to run this application.
org.springframework.core-3.0.1.RELEASE-A
com.springsource.org.apache.commons.logging-1.1.1
org.springframework.beans-3.0.1.RELEASE-A
For the future use, You can download the required jar files for spring core application.
To run this example, you need to load only spring core jar files.
To load the jar files in eclipse IDE, Right click on your project - Build Path - Add external archives - select all the required jar files - finish..
3) Create Java class
In such case, we are simply creating the Student class have name property. The name of the student will be provided by the xml file. It is just a simple
example not the actual use of spring. We will see the actual use in Dependency Injection chapter.
To create the java class, Right click on src - New - class - Write the class name e.g. Student - finish.
Write the following code:
package com.dzosoft;
public class Student {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void displayInfo(){
System.out.println("Hello: "+name);
}
}
This is simple bean class, containing only one property name with its getters and setters method.
This class contains one extra method named displayInfo() that prints the student name by the hello message.
This is simple bean class, containing only one property name with its getters and setters method. This class contains one extra method named displayInfo() that prints the student name by the hello message.
4) Create the xml file
To create the xml file click on src - new - file - give the file name such as applicationContext.xml - finish. Open the applicationContext.xml file, and write the following code: