Create a maven project with quick-start template, refer to this post in case you don’t know how to create one. Next, open the pom.xml and enter these spring dependencies which will be used by our sample app.

<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>3.2.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>3.2.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>3.2.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>3.2.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>3.2.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency> 

Next, We’ll make a class to configure it in the spring container as bean to use. Let’s create a class that will simply print out the Poem, First we create an interface “Poem”

public interface Poem {
    public void recite();
}

And the concrete implementing class

public class SimplePoem implements Poem {
    String poem="Hello Spring World!!";
    public void recite(){
        System.out.println(poem);
    }
}

Next, add the spring config file in the class path (APPLICATION_ROOT/src/main/resources/spring-config.xml) to configure SimplePoem bean in it like:

 
<?impls.di.xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<bean id="poem" class="impls.di.annotation.reference.SimplePoem" />

</beans>

Finally, let’s put the Main class to fire up the code:

public class Main {
    public static void main(String... args){
        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-config-sample.xml");
        Poem poem = (Poem)ctx.getBean("poem");
        poem.recite();
    }
}