报错信息
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!";
}
}
本文详细介绍了在SpringBoot项目中遇到404错误时的排查与解决方法,包括检查controller包及类的创建、确认DemoApplicationTests类的正确编辑、以及验证URL路径与Controller映射是否一致。
5万+

被折叠的 条评论
为什么被折叠?



