Spring Hello World

In this tutorial, we will create our first Spring project Hello World.

 

1. Technologies used

  • Spring 3.2.8.RELEASE
  • Maven 3.0.5
  • Eclipse 4.2
  • JDK 1.6

 

2. Project structure

We create a standard Java project.

Spring-Hello-World-1

 

3. Spring dependencies

We add the Spring dependencies in Maven’s pom.xml file.

We run the command : mvn clean install to download Spring libraries and put them into Maven’s local repository.

 

4. Spring bean

It’s an object that is managed by the Spring IoC container.

In our example, it have one attribute and a method to display Hello World message.

 

5. Bean configuration file

It holds Spring configuration metadata that represents how Spring IoC container to manage the beans in our application.

So, all Spring beans are created with the configuration that we supply to the container in beans.xml file.

File : beans.xml :

 

6. Run It

We will use the piece of code below to load Spring IoC container and retrieve our bean to execute the sayHello() method.

 

Result :

Hello Walid!

 

Download  source code