Setup Spring project in Eclipse with Maven

Updated for Spring 5+

So far we have seen, what is spring framework and why to use it in Java application development. In this particular article we will see how to get started with spring in Eclipse and how to setup a initial Spring project.

Lets take a look at required things before we try to setup a spring project in Eclipse IDE, following are minimal requirements.

1) Java 6+
2) Maven
3) Eclipse IDE

Setup Spring project in Eclipse using Maven

1) Requirement Testing

1.1) Java : Before we start configuring lets test our system for required tools, make sure you have Java installed in your class path:

techie@techie-Satellite-L50-B:~$ java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

1.2) Now lets test for maven installation, supply following command to test if maven is already there:

techie@techie-Satellite-L50-B:~$ mvn -version
Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.8.0_60, vendor: Oracle Corporation
Java home: /usr/lib/jvm/jdk1.8.0_60/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.16.0-50-generic", arch: "amd64", family: "unix"

1.3) Make sure you have a working Eclipse IDE with you.

2) Create a simple Java project with maven

Supply following command to command line, here -DgroupId=com.tbNext.sample is the base package of the application and -DartifactId=SampleSpringMaven is the name of project.

mvn archetype:generate -DartifactId=SpringMaven -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Now you should see a BUILD SUCCESS massage something like this:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] >>> maven-archetype-plugin:2.3:generate (default-cli) @ standalone-pom >>>
[INFO] <<< maven-archetype-plugin:2.3:generate (default-cli) @ standalone-pom <<<
[INFO] --- maven-archetype-plugin:2.3:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-webapp:1.0
[INFO] ---------------------------------------------------------------------------- [INFO] Parameter: basedir, Value: /home/techie
[INFO] Parameter: package, Value: com.tbNext.sample
[INFO] Parameter: groupId, Value: com.tbNext.sample
[INFO] Parameter: artifactId, Value: SampleSpringMaven
[INFO] Parameter: packageName, Value: com.tbNext.sample
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: /home/techie/SampleSpringMaven
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.666s
[INFO] Finished at: Sat Oct 03 14:52:49 IST 2015
[INFO] Final Memory: 11M/124M
[INFO] ------------------------------------------------------------------------

3) Make maven project compatible to eclipse

By default maven projects are not compatible to eclipse, just go inside the project directory and supply following command to make it compilable to Ecllipse IDE.

techie@techie-Satellite-L50-B:~$ cd SampleSpringMaven/ techie@techie-Satellite-L50-B:~/SampleSpringMaven$ mvn eclipse:eclipse

If everything goes right, you should see something like below on your console:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building SampleSpringMaven Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] >>> maven-eclipse-plugin:2.9:eclipse (default-cli) @ SampleSpringMaven >>>
[INFO] <<< maven-eclipse-plugin:2.9:eclipse (default-cli) @ SampleSpringMaven <<<
[INFO] --- maven-eclipse-plugin:2.9:eclipse (default-cli) @ SampleSpringMaven ---
[INFO] Using Eclipse Workspace: null
[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER
[INFO] Not writing settings - defaults suffice
[INFO] Wrote Eclipse project for "SampleSpringMaven" to /home/techie/SampleSpringMaven.
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.145s
[INFO] Finished at: Sat Oct 03 14:56:24 IST 2015
[INFO] Final Memory: 9M/150M
[INFO] ------------------------------------------------------------------------

Here we are done with creating a simple java project in maven.

4) Import project to eclipse

Now lets import this project to Eclipse IDE, open your ide and import the project, using import > existing project in workspace

5) Now we have simple Java project imported in eclipse, lets make it a spring project.

5.1) Adding spring dependency(pom.xml)
Replace pom.xml content with following:

<project xmlns=""



Now go back to maven console and supply following command onece again, it will download and add required dependencies to the project:

mvn eclipse:eclipse

Go back to Eclipse, refresh the project and make sure you have all the required dependencies in Project > Properties > Java Buid Path > Libraries

5.2) Add a spring configuration file /src/main/resources/spring-conf.xml Add a spring configuration file to the project resources folder, with following content

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

All the application beans entries will go here, we are done with creating a Spring project uisng maven.

6) Run application

6.1) Create a sample bean class

package com.tbNext.beans;

public class SampleBean {
	public void printMe() {
		System.out.println("Hello World !");

6.2) Add the entry to spring-conf.xml

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

	<bean class="com.tbNext.beans.SampleBean" id="sampleBean"></bean>


6.3) Add a application class with main method: /src/main/java/com/tbNext/App/

package com.tbNext.App;

import org.springframework.context.ApplicationContext;

import com.tbNext.beans.SampleBean;

public class Application {
	public static void main(String args[]) {
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext(

		SampleBean bean = (SampleBean) applicationContext.getBean("sampleBean");


6.4) Now run project as Java Application, you should see Hello World printed on the console.

Download Complete Project Scource Code from GitHub: Here

Here we are done with creating a simple spring project using maven and importing it in eclipse. In upcoming blogs we will see more about spring framework.

About The Author

Nagesh Chauhan

Nagesh Chauhan has 8+ years of software design and development experience in variety of technologies like - Core Java, Java 8 (Streams, Lambda), J2EE (Servlet, JSP), Spring Framework (MVC, IOC, JDBC, SECURITY etc), Spring Boot and Microservices, Kafla, Redis, Cassandra and Spark.