【问题解决】This application has no explicit mapping for /error, so you are seeing this as a fallback.

 完整报错如下:

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

Mon Nov 19 10:43:58 CST 2018
There was an unexpected error (type=Not Found, status=404).
No message available

上面这句话大概的意思“这个应用没有明确的映射/错误,所以你才会看到这样一个返回结果”。

针对以上错误出现的可能有一下几点:

1)Application启动类的位置不对

要将Application类放在最外侧,即包含所有子包spring-boot会自动加载启动类所在包下及其子包下的所有组件,下面举例说明。

在这总结确认了目前的三种错误案例 

第一种,Application启动类直接放在了java包下面,这个在编译器就会报错

【问题解决】This application has no explicit mapping for /error, so you are seeing this as a fallback._第1张图片

第二种,controller类跟Application启动类在同级包的不同包下边

【问题解决】This application has no explicit mapping for /error, so you are seeing this as a fallback._第2张图片

第三种,启动类范围小于组件的位置范围

【问题解决】This application has no explicit mapping for /error, so you are seeing this as a fallback._第3张图片

正确位置:在组件的同包或者组件的外层包内都可以,总之启动类的位置范围应大于或者等于组件所在位置。(原因就是上面那句不明觉厉的话)

【问题解决】This application has no explicit mapping for /error, so you are seeing this as a fallback._第4张图片

2)在springboot的配置文件:application.yml或application.properties中关于视图解析器的配置问题(暂未碰到,后期碰到后再补充):

当pom文件下的spring-boot-starter-paren版本高时使用:spring.mvc.view.prefix/spring.mvc.view.suffix
当pom文件下的spring-boot-starter-paren版本低时使用::spring.view.prefix/spring.view.suffix

3)控制器的URL路径书写问题:

@RequestMapping(“xxx”) ,实际访问的路径与”xxx”不符合

【问题解决】This application has no explicit mapping for /error, so you are seeing this as a fallback._第5张图片

【问题解决】This application has no explicit mapping for /error, so you are seeing this as a fallback._第6张图片

【问题解决】This application has no explicit mapping for /error, so you are seeing this as a fallback._第7张图片

 

你可能感兴趣的:(错误记录并解决)