0

I am new to spring Boot and followed some basic steps while creating a simple web application.

What i did is i created a folder like- src/main/webapp/WEB-INF/jsp and inside jsp i created home.jsp file Then a controller class where i provided a path via @RequestMapping("/") function. But still i am not able to view my .jsp file. Please help

Structure

Controller class

Spring Boot Application

Application Properties

pom.xml

pom.xml- http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>demo</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</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.apache.tomcat.embed</groupId>
       <artifactId>tomcat-embed-jasper</artifactId>
       <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

2 Answers2

0

Try to separate your main and your controller packages. I suggest that you add another package : com.example.demo.controller and change your controller class to that package

Also try to change the @Controller annotation to @RestController

Ennar.ch
  • 659
  • 1
  • 8
  • 26
0

Probably isn't relevant anymore but might help other people: Try extending SpringBootServletInitializer.

public class demoApplication extends SpringBootServletInitializer {

Daniel
  • 1,895
  • 9
  • 20