SpringBoot项目访问网页空白页报错:Whitelabel Error PageThis application has no explicit mapping for /error

本文详细介绍了在SpringBoot项目中遇到404错误时的排查与解决方法,包括检查controller包及类的创建、确认DemoApplicationTests类的正确编辑、以及验证URL路径与Controller映射是否一致。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

报错信息

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

Sat Feb 29 16:42:04 CST 2020
There was an unexpected error (type=Not Found, status=404).
No message available
在这里插入图片描述

方法1:看是否在\src\test\java\com\example\demo目录下创建了controller包,在controller包里创建Controller类

在这里插入图片描述

方法2:是否正确编辑DemoApplicationTests类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

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

在这里插入图片描述

方法三:是否地址输入错误
http://localhost:8080/test

这里的“/test”取决于HelloController类中 @RequestMapping("/test") 引号里的内容!
在这里插入图片描述

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @RequestMapping("/test")
    public String hello(){
        return "hello world!"; 
    }
}
以上是针对我本人在学习过程中遇到的问题,方法不够全面,也可能是其他的原因。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值