Search Tutorials


Spring MVC Tutorials | JavaInUse



Configuring the Development Environment



Overview

In this chapter we will do the project setup which will be required throughout this series.
We will be creating a Maven project with minimum dependencies added to POM for getting Spring MVC up and running.
In Future chapters further dependencies will be added to the POM.xml as and when required.

Lets Begin

For this series we will be using
1. Eclipse IDE(Luna)
2. Apache Tomcat(version 7)

We will be creating a Maven Project and also configuring Tomact in POM for deployment.
Open the Eclipse IDE.
1. Go to File->new->other->Maven Project.Click Next Button.

final-mvc1-1

final-mvc1-2
2. If not already selected, select Use default Location. Click Next Button.

final-mvc1-3
3. Select Archtype as maven-archtype-webapp. Click Next Button.

final-mvc1-4
4. Enter the values for Group Id as com.javainuse and Artifact Id as employee-management-system.

final-mvc1-5
5. Click Finish

Our Maven Web Project is now created. We will now modify the pom.xml file as follows-
1. Add dependencies required for Spring MVC.
2. Add the build plugins required for maven and tomcat configurations.

After modification our pom.xml file is as follows-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.test</groupId>
	<artifactId>employee-management-system</artifactId>
	<packaging>war</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<name>employee-management-system Maven Webapp</name>
	<url>http://maven.apache.org</url>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>4.0.5.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>4.0.5.RELEASE</version>
		</dependency>
	</dependencies>
	<build>
		<finalName>employee-management-system</finalName>
		<plugins>
			<plugin>
				<groupId>org.apache.tomcat.maven</groupId>
				<artifactId>tomcat7-maven-plugin</artifactId>
				<version>2.2</version>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.4</version>
			</plugin>
		</plugins>
	</build>
</project>


Here we have configured the tomcat in the pom itself. Now run the following two Maven commands in sequence
1. clean:install - This will download the dependencies required and build the war file.
2. tomcat:run - This will start the Tomcat and install the war file in Tomcat container. In the console you will se the deployment details as follows

mvc1-9
After running these commands open the browser and go to http://localhost:8080/employee-management-system

mvc1-10
So our Eclipse and Tomcat are now configured. Eclipse project structure at the end of this chapter is as follows-
final-mvc1-6

Download Source Code

Download it - Spring-MVC Project Setup

What Next?

In the next chapter will implement Simple MVC.