Create java spring hello world

Create java spring hello world

This demo will show you how to Create java spring hello world. Basically this project is standalone java spring project to show you how to load bean through ClassPathXmlApplicationContext as standalone application and finally print message Hello World! on console. Please follow below steps:

Below technology have been used:

  • Maven 3
  • JDK 1.6
  • Eclipse Kepler
  • Spring 2.5.6


  • Create Maven project in eclipse : Open your eclipse –>Click File –> New –> Maven Project

Create java spring hello world


  • It will open New Maven project window click Next

Create java spring hello world


  • Next window choose as below then click Next

Create java spring hello world


  • Next window enter as below once entered all click Finish

Create java spring hello world

  • Now you will project name SpringStandAloneHelloWorld created in eclipse
  • Open your pom.xml file and copy paste below code
<project xmlns="" xmlns:xsi=""







  • Maven creates default class when use quick start java project.Copy and paste below code to file:

package com.javahonk;

import org.springframework.context.ApplicationContext;

 * Hello world!
public class App {
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext("Bean.xml");

		HelloWorldBean obj = (HelloWorldBean) context.getBean("helloWorld");



  • Create bean class and copy paste below code:
package com.javahonk;

public class HelloWorldBean {
	private String message;

	   public void setMessage(String message){
	      this.message  = message;

	   public void getMessage(){
	      System.out.println("Message : " + message);


  • Now create source folder name resources inside project. Right click on project –>  Click New –> Choose Source Folder and create folder name resources

Create java spring hello world

  • resources folder automatically will be added to java classpath and we need bean.xml file available at runtime to load. Now create Bean.xml file inside resources folder and copy paste below code in it;
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns=""

   <bean id="helloWorld" class="com.javahonk.HelloWorldBean">
       <property name="message" value="Hello World!"/>



  • We are ready now. Final project structure will look as below:

Create java spring hello world

  • To run project: Right click class –> Run As –> Java Application you will see below Hello World! message on console:

Create java spring hello world


  • That’s it

download2 Download project: SpringStandAloneHelloWorld

Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *