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

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

报错信息

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

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

Sat Dec 23 15:25:59 CST 2017
There was an unexpected error (type=Not Found, status=404).
No message available

解决方法

1、引入thymeleaf引擎

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

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

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

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

@Controller
public class UlevelController {
    @RequestMapping(value="getUList", method=RequestMethod.GET)
    public String getUlevelList() {
        ………………
        return "ulevel/ulevelList";
    }
}

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

@Controller
@RequestMapping(value="/hhllow")
public class UlevelController {
    @RequestMapping(value="getUList", method=RequestMethod.GET)
    public String getUlevelList() {
        ………………
        return "ulevel/ulevelList";
    }
}

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

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

展开阅读全文

没有更多推荐了,返回首页