Steps to create Spring MVC project in STS with Maven

This page will help you to learn, what are the steps we need to follow to create Spring MVC project with the support of STS and Maven. There are couple of ways creating the WEB project. This is one of the way of creating as Maven Project.

File ==> New ==> Others

Search for Maven and choose Maven Project.

No need to do anything in below screen, click on Next

Search for webapp in Filter section and select the below show webapp

Enter the Group Id and Artifact as whatever you like,


push monolithic application into pcf – 1

In previous posts, we have seen how to create Microservices application with Spring Boot technology and push it into the pivotal cloud foundry. Since Spring Boot works on the concept of auto configuration, we easily pushed Spring Boot application into PCF without worrying about application configuration or running environment like Tomcat server and all.

When it come to normal Spring MVC application, Tomcat or any other web/application server is compulsory to use to run the application. Now the question is, how can we push monolithic Spring MVC application in Pivotal?

To get clarification about above question, we need to follow below steps.

  1. Create Spring MVC application in local environment.
  2. Test to get confirmation either working as expected or not in locally configured server.
  3. When it’s working in locally, push the same jar/war file into pivotal cloud foundry.
  4. Test by using application route provided by pivotal

Step1: Creating Spring MVC application

I am trying to create a sample application of using the below techstack to push that application into Pivotal Cloud Foundry. This application does not contain any database interaction.

Java – 1.8

Spring – 5.x

Maven – 3.5.x

STS – 4

Tomcat – 8.5

If you are not aware of how to create Spring MVC project in Spring Too Suite (STS) as Maven project. Follow the steps explain in this page.

The project might get generated in different structure. The below is my project structure look like,


<project xmlns=""
    <name>monolithic-springmvc Maven Webapp</name>




<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="" version="2.5"

 <description>Monolithic Spring MVC application created for
  pushing into pivotal cloud foundry</description>



spring-servlet.xml: This file name you can change as you like. But, you should configure the same name in above web.xml file wherever configured. 

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

    <mvc:annotation-driven />
    <mvc:default-servlet-handler />
  base-package="com.monolithic.springmvc.controller" />

    <bean id="viewResolver"
 <property name="viewClass"
 <property name="prefix" value="/WEB-INF/views/"/>
 <property name="suffix" value=".jsp"/>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Monolithic Spring MVC - Index</title>
 <h2>Hey Monolithic</h2>
     <a href="welcome?name=JavaIsOcean">Click Here</a>


<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Monolithic Spring MVC - Welcome</title>
 <h2>Hello ${name}</h2>

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

public class MonolithicController {
    String message = "Welcome to Monolithic Spring MVC Application!!!";
    public ModelAndView showMessage(@RequestParam(value = "name", required = false, 
        defaultValue = "JavaIsOcean") String name) {
       ModelAndView mv = new ModelAndView("welcome");
       mv.addObject("name", name);
       mv.addObject("message", message);
       return mv;

Let’s build the application source code by using the command of mvn clean install and get war file is generated or not in target directory. If the war file is not generated, your code is not correct. If you don’t wish to write all these code, you can also download from So, now creating the sample Spring MVC project completed.

Step 2: Test application in local server:

To complete this step, we need a web/application server which is running locally. If you have already have configured any server, you can deploy the generated war file into it and test. Otherwise we need to download and configure.

To make it simple, I have downloaded the tomcat server with the version of 8.5 from official Tomcat website as a zip file and extracted locally. There might be a chance of facing startup issues. To avoid that, do the highlighted settings changes in your local as well.

Once you run the project successfully, you will get the output as index page As on when you hit the below URL. URL will be the combination of  host + port+ context name. Output look like below,

You will get the output as below, as on when you click on the Click Here hyper link.

So, our step 2 also completed.

Step 3: Push war file into Pivotal Cloud Foundry:

You should have valid credentials to login into Pivotal account prior doing any operations with Cloud foundry environment. If you don’t have follow these instructions to register and access in Pivotal and get 2 GB of free space.

If you already have valid account details, login into pivotal by using Cloud Foundry CLI with the command of cf login. If you didn’t have installed Cloud Foundry, follow these instructions.

Navigate into the target directory or where your war file located, and issue the below command to push into cloud foundry.

cf push monolithic-springmvc -p monolithic-springmvc.war

cf push  – is the command to push application into cloud foundry
monolithic-springmvc –  is the application name I am passing
-p  – is the parameter to specify the pushing file path where it located

Once we issue the above command, we will see the pushing progress like below,

Once it completed pushing and starting the application, you can access the URL, which is called as route in Cloud foundry terminology. In this case, is the route to access application. Look at the below screen to know about application details in pivotal application manager.

So, pushing war file into cloud foundry account is completed. Let’s move on to last step of testing the application.

Step 4: Test by using application route:

As I explained in Step 3, once we push application successfully in pivotal cloud foundry, it will generate a route to access application. As on you open the route, you will get the same output what we have got in Step 2 of testing in local tomcat environment. Look at the below screens,

We will get the below screen as on when we hit the Click Here hyper link shown in above screen,


Note: If you observe the above URL / Route, we are not passing any application context name like how we access in local. That will be taken care by Pivotal.