Tech in T: depth + breadth‎ > ‎Tools - Business‎ > ‎Java‎ > ‎Spring‎ > ‎

Hello World

Here is the Spring 3.0 HelloWorld in Eclipse IDE for Java Developers. Thanks to

$ java -version
make sure it is newer than java 5 (1.5).

1. Make a new java project in eclipse.

Make a folder at the root of the project. Name it lib


2. Download Spring Framework 3 (e.g. This includes documentations also.

Extract it somewhere and copy the contents of its dist directory to the lib directory you just made, also copy spring-framework-3.1.0.M1-with-docs\spring-framework-3.1.0.M1\projects\spring-build\lib\ivy\commons-logging.jar  to the lib directory in eclipse project.


3. Add all the contents of the lib directory as jar files to the project build path (class path)


4. Create package net.roseindia. In this package
Create a java file

package net.roseindia;

public class Spring3HelloWorld {

public void sayHello(){

System.out.println("Hello Spring 3.0");




In this section we will use the Spring framework to manage the Spring3HelloWorld bean, and then get the bean from the Spring runtime environment (Spring context) and the call the sayHello() method.


5. create a new xml (SpringHelloWorld.xml) in the src directory of the eclipse project.


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

<beans xmlns=""

xmlns:xsi="" xmlns:aop=""


<bean id="Spring3HelloWorldBean"

class="net.roseindia.Spring3HelloWorld" />




Spring uses the xml file to configure the spring run-time environment, this file will be referred to by precise name to access bean list

6. create a java file ( into net.roseindia package

package net.roseindia;

import java.util.Map;

import org.springframework.beans.factory.xml.XmlBeanFactory;


import org.springframework.util.Assert;

public class Spring3HelloWorldTest {

public static void main(String[] args) {

XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(


Spring3HelloWorld myBean = (Spring3HelloWorld) beanFactory






we have created the instance of XmlBeanFactory and the retrieved the "Spring3HelloWorldBean". Then we can call the sayHello() method on the bean. The XmlBeanFactory  class is extension of DefaultListableBeanFactory that reads bean definitions from an XML document.


Eclipse :   Run as --> Java Application



Jan 1, 2010 6:49:57 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions

INFO: Loading XML bean definitions from class path resource [SpringHelloWorld.xml]

Hello Spring