Easy learning with example program codes

spring boot + Spring MVC + Maven + JSP example

Spring boot is a module of spring framework which is used to create stand-alone, production-grade Spring based Applications with minimum programmer’s efforts. It is developed on top of core spring framework. The main concept behind spring boot is to avoid lot of boilerplate code and configuration to improve development, unit test etc.

Spring boot jsp example

Directory Structure

Spring security

pom.xml file

Modify auto created POM file. We need to add parent in pom to make it a spring boot application. After that add spring-boot-starter-web dependency and java version.

<project xmlns="" xmlns:xsi=""
       <!-- This is a web application -->
	<!-- Tomcat embedded container-->
	<!-- JSTL for JSP -->
	<!-- Need this to compile JSP -->
	<!-- Need this to compile JSP -->
			<!-- Package as an executable jar or war -->

Now, right click on project -> click on Maven -> click on update project -> Popup window will open -> click Ok to update the project.
It is a initializer class which runs a SpringApplication.

package com.codesjava;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
public class App extends SpringBootServletInitializer {
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(App.class);
    public static void main( String[] args ) {, args);  

package com.codesjava;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
public class HelloWorldController {
	private String message = "Hello World";
	public String welcome(Map<String, Object> model) {
		model.put("message", this.message);
		return "helloWorld";


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<%@ taglib prefix="spring" uri=""%>
<%@ taglib prefix="c" uri=""%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
	<h2>Spring Boot JSP Hello World Example</h2>
	<h2>Message: ${message}</h2>

spring.mvc.view.prefix: /WEB-INF/views/
spring.mvc.view.suffix: .jsp

Hit http://localhost:8080/ in the browser, following output will come.
Spring security

Please follow and like us:

Spring Tutorial

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki