Here I am posting my first very basic example on a very famous Java framework called Spring.
We need following requirements:-
1.Spring 3.0
2.Eclipse
3.JDK 1.6
5 Steps to create Hello World Example in Spring 3.0
1.First create a Java Project in Eclipse:
2.Include the Spring 3.0 jar in Project:
Right Click on Project Then Goto
Build Path->Configure Build Path
Then give the path of the jars where you have put it.
3.Create HelloWorld Class:
package com.tutorialjam.tutorial.beans;
public class HelloWorld {
private String guestName;
public void setGuestName(String guestName)
{
this.guestName = guestName;
}
public String sayHello()
{
return "Hello "+guestName+"!!!";
}
}
4.Create a xml file in root folder that includes:
5.Create A class that has main() method:
package com.tutorialjam.tutorial.app;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.tutorialjam.tutorial.beans.HelloWorld;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
ApplicationContext context= new ClassPathXmlApplicationContext("beans.xml");
HelloWorld hello= (HelloWorld) context.getBean("helloworld");
System.out.println(hello.sayHello());
}
}

No comments:
Post a Comment