Develop Hello World example using Spring 3.0 Framework

Hello World Example in Spring 3.0 Framework.



Spring 3.2 MVC insert and retrieve blob from the database The hidden tag The errors tag net.roseindia.dao net.roseindia.service net.roseindia.model net.roseindia.controller Spring 3.2 MVC Hibernate Example Spring 3.2 MVC, Upload File in a specific folder Spring 3.2 MVC Form Handling The textarea tag The options tag The option tag The select tag The radiobuttons tag The radiobutton tag The checkboxes tag mvc:default-servlet-handler Static Resources Configuration View Controllers Configuration View resolvers Spring 3.2 MVC Hello World Example Content Negotiation Configuration Interceptors Configuration using Java or XML Customizing the MVC Java config or XML Namespace MVC Java Config or the MVC XML Namespace Servlet container initialization through code Support for ETag The checkbox tag Autogenerated logical view name through RequestToViewNameTranslator Modification in conventional ModelAndView ControllerClassNameHandlerMapping class for handling convention mapping The password tag The input tag The form tag Form Tag library configuration Customizing the Default Error Page @ExceptionHandler & @ResponseStatus annotation Multipart support for file upload in Spring MVC Themes and Theme resolvers in Spring MVC Locales in Spring MVC ContentNegotiatingViewResolver Redirecting and forwarding to views Chaining of Multiple view resolvers View Resolving through ViewResolver interface Requests Intercepting through a HandlerInterceptor Defining handler methods using @RequestMapping annotation Spring 3.2 Asynchronous Request Processing @RequestMapping annotation for mapping requests @Controller annotation for defining new controller

Spring 3 Hello World Example


In this section we will download spring, create new project in Eclipse IDE and then write simple Hello World application. We will finally run the application in the Eclipse IDE.

In this section you will learn how to download, create a new project in Eclipse IDE, add Spring 3.0 library files, the write simple program. Finally we will test the example code in Eclipse IDE.

Let's start developing "Hello World" example code

Step 1:

The Spring 3.0 at least requires JDK 5. So, make sure you have JDK 5 or above. Open dos prompt if you are using windows and type java -version. This will display the version of Java installed on your machine as shown below:

C:\>java -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)


 If you don't know how to install Java read it at

Step 2:

Download Eclipse IDE from Eclipse download site at Installing Eclipse IDE is easy task, just extract the downloaded file and you will find the eclipse.exe in the extracted folder. To run the IDE, double click on the eclipse.exe file. Read more at

Step 3:

Download the latest version of Spring 3 from For this tutorial we have downloaded, which contains the documentation also. After extracting the file we got the following directories:

Step 4:

Now we will create a new project in Eclipse IDE and then add the library files.

Click next. Give any name to the project, say "Spring 3" and then click on the "Finish" button.

Eclipse will create a new project.

Step 5:

Create a new folder "lib" in the project space to hold the Spring 3.0 libraries. Right click on the "Spring3" in the project explorer and then select new folder option as shown below:

Then in the next screen enter "lib" next to the "Folder name" text field and click on the "Finish" button.

Step 6:

Now we will add the Spring 3. libraries to the project. Extract the "" file if you have not extracted. Now go to the "dist" directory of the and then copy all the jar files (Ctrl+C) and paste on the lib directory (of our project) in the Eclipse IDE.


Then find the commons-logging.jar from extracted folder and also copy this file into Eclipse IDE. You will find this library into spring-framework-3.0.0.RELEASE-with-docs\spring-framework-3.0.0.RELEASE\projects\spring-build\lib\ivy folder.

Step 7:

Now all all the libraries to "Java Build Path". Right click on the "Spring3" in project explorer and then select properties. Then select "Java Build Path" --> Libraries and then click on the "Add JARs" button. And add all the libraries to Java Build Path.


Then click on the "OK" button. This will add all the libraries to the project. Now we can proceed with our Spring 3 Hello World example.

Step 8:

Create a new package net.roseindia to hold the java files. Right click on the "Spring3" and then select New --> Package. Then provide the package name as net.roseindia and click on the "Finish" button.


Step 9:

Create a new Java file under the package net.roseindia and add the following code:

package net.roseindia;

public class Spring3HelloWorld {
public void sayHello(){
System.out.println("Hello Spring 3.0");
In the above class we have created a method sayHello() which prints the "Hello Spring 3.0" on the console. 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. In the next step we will xml file which will be used as Metadata to configure the bean.

Step 10:

Now create a new xml (SpringHelloWorld.xml) file using Eclipse IDE.


Add the following code to the xml file:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
xmlns:xsi="" xmlns:aop=""

<bean id="Spring3HelloWorldBean"
class="net.roseindia.Spring3HelloWorld" />

The above xml file declares the spring bean "Spring3HelloWorldBean" of the class net.roseindia.Spring3HelloWorld. The <bean .../> tag is used to declare a bean in the xml file. Spring uses the xml file to configure the spring run-time environment. Spring framework manages the beans in our program. In the next sections we will learn Spring core components in detail. Note: You should move the SpringHelloWorld.xml file into src directory of the project. Jut use mouse to drag and dop in the src folder.


Step 11:

Now create a java file ( into net.roseindia package and add the following code:

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
In the above code 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. In our case it reads the bean definitions from SpringHelloWorld.xml file.

Step 12:

To run the code in Eclipse open in the editor and then right click and select Run as --> Java Application. This execute the file and following output will be displayed in the console.

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 3.0


In this section we developed Hello World example that uses the Spring 3.0. In the next section we will learn about @configuration, and see how this annotation can used in the Spring 3.0 application.

Download Code


Share on Google+Share on Google+

Develop Hello World example using Spring 3.0 Framework

Posted on: January 1, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Develop Hello World example using Spring 3.0 Framework   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
September 22, 2012
Problem in main class

Its not working properly :(
September 27, 2012

i m new to springs i have wrote as it is the code but there is no output in the console so please help me
Sandeep Gupta
November 11, 2012
Sample Spring Applicationm

I have tried to build this sample application using ecliose tools. I have followed all the step but getting NoClassnotfound Exception . Solution: Common Logging jar was missing after setting this jar in class path. sample Application is running perfectly.
Alexander Baggett
November 13, 2012
Deprecated Code used here

XmlBeanFactory is deprecated now. This needs to be updated with a different approach.
November 30, 2012
Unable to extract files

Hi, It is showing as compressed file is invalid/corrupted when we try to open the downloded code. Please make the code readable. -Thankyou Shilpa C S
July 24, 2013
Spring 3 Hello World Example

Thanks very simple and efficient
September 10, 2013
Add log jar

add commons-logging jar to run this example
Pramod Nandagudi
November 22, 2013
Starter class missing error

i think ur starter class is missing or u have coded the main method improperly. check for compilation errors before running the code.
Ranjani Murugesan
April 15, 2014
Spring and Hybernate

Its good for all..