Tuesday, May 22, 2012

Spring Framework-A Simple Hello Program



First to develop applications with the Spring framework need to setup the environment . Development requirements  are-
1. Eclipse.
2.JDK 1.6.0
3.Spring framework 3.0(Click here to download).
Add the spring jar files into CLASSPATH or Eclipse Library.

1.create a simple java project.The directory structure of program as-
Create class Triangle.java
package com.test;

public class Triangle
{
public void draw()
{
System.out.println("Hello Triangle");
}

}


create class DrawApp.java(Main Class)
package com.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class DrawApp {

public static void main(String a[])
{
ApplicationContext context=new ClassPathXmlApplicationContext("spring.xml");
Triangle tri=(Triangle) context.getBean("triangle");
tri.draw();

}
}
create Xml file spring.xml


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<beans>
<bean id="triangle" class="com.test.Triangle">
</bean>
</beans>




Now run the project and output is-

Hello Triangle



Click to Download Example With Jar file


For Further Reading,
General, Java, spring

0 comments:

Post a Comment


 

Site Status

Man Behind Technical Today

Hello, I am Navin Bansal. I am a student of MCA in Rajsthan Institute of Engineering and Technology and owner of this blog. I share my view and ideas among people.