Image of Create a Web Application With Spring Boot


Table of Contents


This guide shows how to create a simple MVC web application using Spring Boot.


  • Eclipse IDE (neon release)
  • Maven 4
  • Java 1.8

1. Create maven web project

Open eclipse then create a new maven web project and name it as SpringBootWebJsp.

The structure of the generated projects look like the following:

folder structure

2. pom.xml

After creating the web project, the first step is to configure Spring Boot inside pom.xml, so we add the following as a parent dependency:


Spring Boot exposes a starter called spring-boot-starter-web which automatically imports all the required jars needed to setup a typical Spring MVC application and automatically configures the view resolver and the servlet dispatcher of the application so that the developer focuses on the development rather than the configuration, so we add the starter as a dependency:


Since we’re using JSP as the front end technology, we need to add the following dependency in order to be able to compile JSP and make use of its features:


That’s all, just 2 dependencies can make your MVC application up. Below are the auto-imported jars:


This is the whole pom.xml for reference:

<project xmlns="" xmlns:xsi=""

P.S: when using JSP as a front end technology, you should make sure to set the “packaging” attribute as war not jar, since Spring Boot team claimed that currently there is limitations for supporting JSP inside jar file ( the view resolver wouldn’t map correctly).


The second step is to create the Spring Boot initializer class, this is the entry point of our application. When annotating a class with @SpringBootApplication, we’re configuring our application to run over the embedded servlet container provided by Spring Boot (tomcat by default).

package com.programmer.gate;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
public class Application{
    public static void main(String[] args) {, args);


Spring Boot auto configures the view resolver and the dispatcher servlet of the web application and provides us a way to define our own configuration using

So we create under src/main/resources and define the following properties:

home.message= Programmer Gate

Here we’re configuring the view resolver to map the views to files of type jsp under “WEB-INF/jsp/”. We also change the default port of the embedded tomcat to be 9093, as well as defining other business message properties to be used later on inside our application.

5. home.jsp

In this tutorial, we’re creating a very simple MVC application which displays a welcome message to the end user, so we create a very basic jsp file called home.jsp under WEB-INF/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">
    <h1>Welcome to ${message} </h1> 


Now we create our main controller named HomeController under com.programmer.gate and we define it to serve requests coming from the root path as the following:

package com.programmer.gate;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
public class HomeController {
    private String message;
    public String welcome(Map<String, Object> model) {
        model.put("message", this.message);
        return "/home";

Our controller simply reads the welcome message from and then redirects to home.jsp.

7. Deploy the application

Following are the steps to deploy our application:

  • Right click pom.xml -> run-as -> Maven install
  • Maven generates a war file called SpringBootWebJSP-0.0.1-SNAPSHOT.war inside target folder
  • Open cmd, then run the war using: java -jar SpringBootWebJSP-0.0.1-SNAPSHOT.war

Here we go, our application is up and ready to serve requests at port 9093.

That’s it, I hope you like it. For clarifications please leave your thoughts in the comments section below.


This guide shows how to create a simple MVC web application using Spring Boot.

Next Steps

If you're interested in learning more about the basics of Java, coding, and software development, check out our Coding Essentials Guidebook for Developers, where we cover the essential languages, concepts, and tools that you'll need to become a professional developer.

Thanks and happy coding! We hope you enjoyed this article. If you have any questions or comments, feel free to reach out to

Final Notes