springboot项目浏览器报错:There was an unexpected error (type=Not Found, status=404).

左手的ㄟ右手 2022-06-03 08:27 650阅读 0赞

springboot项目浏览器报错:There was an unexpected error (type=Not Found, status=404).

报错信息

springboot+thymeleaf项目,运行时页面报错信息如下:

  1. This application has no explicit mapping for /error, so you are seeing this as a fallback.
  2. Sat Dec 23 15:25:59 CST 2017
  3. There was an unexpected error (type=Not Found, status=404).
  4. No message available

解决方法

1、引入thymeleaf引擎

查看是否忘记引入了thymeleaf依赖,没有引入则在mawen的pom.xml文件引入,pom.xml文件的thymeleaf引入如下:

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-thymeleaf</artifactId>
  4. </dependency>

2、检查访问地址是否正确

检查访问地址是否写正确,地址应该为controller的路径加上RequestMapping的路径。
如下代码的访问地址为:http://localhost:8080/getUList

  1. @Controller
  2. public class UlevelController {
  3. @RequestMapping(value="getUList", method=RequestMethod.GET)
  4. public String getUlevelList() {
  5. ………………
  6. return "ulevel/ulevelList";
  7. }
  8. }

如下代码的访问地址为:http://localhost:8080/hhllow/getUList

  1. @Controller
  2. @RequestMapping(value="/hhllow")
  3. public class UlevelController {
  4. @RequestMapping(value="getUList", method=RequestMethod.GET)
  5. public String getUlevelList() {
  6. ………………
  7. return "ulevel/ulevelList";
  8. }
  9. }

这里顺便说明,如果访问的是hello.html,但是hello.html不存在,不是抛出404的错误,而是500的错误,如下信息:

  1. Error resolving template "/hello", template might not exist or might not be accessible by any of the configured Template Resolvers

如果看到如上信息,那么就要检查下模板文件是否存在,以及文件名称是否编写正确了。

3、包路径写对

application.java文件的包必须是项目下的父路径,其他类的包路径必须是其子路径,如:
路径

以下是我在其他地方看到的信息
引用

参考:http://412887952-qq-com.iteye.com/blog/2313575
http://quabr.com/36819277/i-keep-getting-this-error-there-was-an-unexpected-error-type-not-found-status

发表评论

表情:
评论列表 (有 0 条评论,650人围观)

还没有评论,来说两句吧...

相关阅读