My question is : from basic which are the necessary jars that should required in Spring and how could we configure Spring project ?

Was it helpful?


Go to Spring home page and download Spring (Here, i am using 2.5.x version)

After installing, put the following jar in your classpath


Here goes a single bean


public class Hello {

    private String message;

    // getter's and setter's



Write a single xml to configure your beans as follows

// app.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="" xmlns:xsi="" xsi:schemaLocation="">
    <bean id="hello" class="">
        <property name="message" value="What do you want ?"/>

Put your app.xml in root classpath

And your psvm

public static void main(String [] args) {
    ApplicationContext appContext = new ClassPathXmlApplicationContext("app.xml");

    Hello hello = (Hello) appContext.getBean("hello");

    hello.getMessage(); // outputs What do you want ?


What is the role of the applicationContext.xml

When using getBean method, it behaves like a Factory pattern. Something like

public class ApplicationContext {

    Map wiredBeans = new HashMap();

    public static Object getBean(String beanName) {
        return wiredBeans.get(beanName);


As said by Spring in Action book

It is a general-purpose factory, creating and dipensing many types of bean.

But, There is more

  • Allows you load files
  • You can publish events
  • It supports i18n (i18n stands for internationalization)

Suppose here goes (root of the classpath)


messsageCode=What do you want ?

To enable i18n, You must define a bean called messageSource to get advantage of our resource, as follows

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="" xmlns:xsi="" xsi:schemaLocation="">
    <bean id="messageSource" class="">
        <property name="basename" value="messages"/>

Now, you can use it

appContext.getMessage("messsageCode", null, null); // outputs What do you want ?

Usually, we do not need to define all of our beans in xml file. You can use annotations (Additional settings needed to enable component scanning) instead of xml, Something like


public class Hello {

    private String message;

    // getter's and setter's


Component annotation says:

Spring, i am a general-purpose bean which can be retrieved through application context

A good resource about Spring is either Spring in Action book or Spring documentation

Advice: read carefully


You can have a look at the article on understanding the webapplicationcontexts and other xml config files in spring

Think this can help you in getting the configurations related to basic spring MVC with ease

You can also use Maven to create and manage projects. You can get an idea about Maven and how to start from here

A directory structure will be created by Maven and there will be a pom.xml inside your project directory. You can mention all dependencies in this file. Eg: for using spring, you can mention the dependency as follows,


If you are using Eclipse as IDE, you need to execute the following command,

mvn eclipse:eclipse

This will create a .project file. You can now import the project into Eclipse IDE and start coding your application.

For beginners, Spring reference documentation and books like Spring in Action and Spring Recipes are very useful

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top