Spring Boot JSP examples 2016-04-14 20:07

Before learning how to use JSP in Spring Boot you need know there are several limitations. You can click here to learn more. In order to show the page you need add tomcat-embed-jasper dependency in pom file. Spring Boot uses an embedded servlet container which is not rendering JSP as default.

Project Structure

    │  └─com
    │      └─henry
    │          └─jsp
    │                  SampleWebJspController.java
        │  application.properties

pom file


java code

public class SampleWebJspController extends SpringBootServletInitializer {

    @Value("${application.message:Hello World}")
    private String message = "Hello World";

    public String welcome(Map<String, Object> model) {
        model.put("time", new Date());
        model.put("message", this.message);
        return "welcome";

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleWebJspController.class, args);


    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>

Start the project with main method and access localhost:8080 you can see the page.


At first I make a directory in src/main like webapp/WEB-INF/jsp and put all jsp in it. When I try to access root path with main method I got 404 page. I found there is no jsp file in jar. I changed the pom file like following

    <!-- dependency here -->


Add spring-boot-maven-plugin in pom file, run maven command mvn clean spring-boot:run and access 'localhost:8080' it works. It means you have to make servlet container found the jsp files. Use maven plugin to package jsp in war or put jsp in META-INF folder.