spring带thymeleaf白标启动错误页面

epfja78i  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(327)

正如标题所示,当我键入地址时 http://localhost:8080/dsh ,我得到以下回应:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Thu Jul 08 19:19:03 WAT 2021
There was an unexpected error (type=Not Found, status=404).
No message available

我试过了 @ComponentScan(basePackages= {"com.mps.expert.controller"}) 在SpringBoot应用程序中,我尝试了许多其他解决方案,但都没有成功。我好像找不到问题。
我的 application.properties 文件为空。
这是项目结构:

这是你的电话号码 ExpertApplication.java :

package com.mps.expert;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages= {"com.mps.expert.controller"})
public class ExpertApplication {

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

}

这是控制器 dsh.java :

package com.mps.expert.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class dsh {
    @GetMapping("/dsh")
    public String plot(Model mdl) {
        return "dashboard";
    }
}

这是 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.mps</groupId>
    <artifactId>expert</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>expert</name>
    <description>spring boot admin</description>
    <properties>
        <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-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

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

</project>
mctunoxg

mctunoxg1#

尝试将此thymeleaf依赖项添加到 pom.xml :

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>      
</dependency>

相关问题