user3094331
user3094331

Reputation: 554

Spring boot Jsp file not found

enter image description here

Spring boot is not able to find the jsp file in the application. I do not know why it is not able to find the jsp file in the given path. Can you please let me know how to resolve it

SpringBootHelloWorldApplication.java

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
    @SpringBootApplication
    public class SpringBootHelloWorldApplication  {

        public static void main(String[] args) {
            SpringApplication.run(SpringBootHelloWorldApplication.class, args);
        }
    }

WelcomeController.java

@Controller
public class WelcomeController {

    @RequestMapping("/hello")
    public String getHello(Model model){        
        model.addAttribute("message", "welcome to the jsp page");
        return "welcome";
    }
}

application.properties

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

welcome.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<html lang="en">

<body>Message: ${message}
</body>
</html>

pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
<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.springboot.application</groupId>
    <artifactId>springbootmvc2</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>springbootmvc2 Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
    </dependencies>        
</project>

Upvotes: 1

Views: 1798

Answers (1)

Alien
Alien

Reputation: 15878

You are missing @SpringBootApplication annotation on main class.

Here is a working example : Spring-Boot-Jsp-Demo

Upvotes: 2

Related Questions