First Time Spring

Very first time in Spring, this is the right place!


  • How to code your first Spring java application?
  • What libraries you need to download?



  • Eclipse Indigo


( 1 ) Create a new Java project

( 2 ) Create a new folder (lib) for the jar files

  • Copy all or the below jars from the downloaded Spring-Framework zip file
  • Add  them to the project build path

( 3 ) Create Java beans ( +

  • Create Shape interface (no need to create an interface, but just to use it for later example!)
  • Create Circle class implementing Shape
  • Place them as show below

package com.hmkcode.beans;

public interface Shape {
	void draw();
	void area();

package com.hmkcode.beans;

public class Circle implements Shape {

	double radius;

	public Circle(){
		System.out.println("Circle has been created!");

	public Circle(double radius){
		this.radius = radius;
		System.out.println("Circle has been created radius = "+radius);

	public double getRadius() {
		return radius;
	public void setRadius(double radius) {
		this.radius = radius;

	public void draw(){
		System.out.println("Drawing Circle");
	public void area(){
		System.out.println("Area = "+Math.PI*Math.pow(radius, 2));

( 4 ) Create Spring XML configuration file (spring-config.xml)

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

		<bean id="circle" class="com.hmkcode.beans.Circle"/>

Place spring-config.xml as shown below

( 5 ) Create Test class (

package com.hmkcode;

import org.springframework.context.ApplicationContext;

import com.hmkcode.beans.Circle;;

public class Main {

	public static void main(String args[]){

		// Laod spring-config.xml file
		ApplicationContext ctx = new ClassPathXmlApplicationContext("com/hmkcode/config/spring-config.xml");

		//get circle bean defined in spring-config.xml file
		Circle circle =(Circle)ctx.getBean("circle");

		//do something with the bean

Run the application you should get

Download Source Code:

Next:Spring XML Configuration