每当我遇到错误时-Whitelabel错误页面此应用程序都没有/ error

时间:2018-08-06 07:15:10

标签: spring spring-boot-maven-plugin

我是Spring Boot的新手,在创建一个简单的Web应用程序时遵循了一些基本步骤。

我所做的是我创建了一个文件夹-src / main / webapp / WEB-INF / jsp,并在jsp内创建了home.jsp文件 然后是控制器类,其中我通过@RequestMapping(“ /”)函数提供了路径。但是我仍然无法查看我的.jsp文件。请帮助

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 个答案:

答案 0 :(得分:0)

尝试将您的主程序包和控制器程序包分开。我建议您添加另一个包:com.example.demo.controller并将控制器类更改为该包

还尝试将@Controller批注更改为@RestController

答案 1 :(得分:0)

可能不再相关,但可能会帮助其他人: 尝试扩展 SpringBootServletInitializer

public class demoApplication extends SpringBootServletInitializer {