【问题标题】:Everytime i am getting error- Whitelabel Error Page This application has no explicit mapping for /error每次我收到错误时 - Whitelabel 错误页面此应用程序没有 /error 的显式映射
【发布时间】:2019-01-13 02:27:39
【问题描述】:

我是 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>

【问题讨论】:

    标签: spring spring-boot-maven-plugin


    【解决方案1】:

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

    同时尝试将@Controller注解改为@RestController

    【讨论】:

      【解决方案2】:

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

      public class demoApplication extends SpringBootServletInitializer {
      
      

      【讨论】:

        猜你喜欢
        • 2016-10-26
        • 2019-05-23
        • 2019-11-10
        • 2020-05-11
        • 1970-01-01
        • 2019-01-26
        • 2020-10-26
        • 2021-07-15
        • 1970-01-01
        相关资源
        最近更新 更多