【异常】This application has no explicit mapping for /error, so you are seeing this as a fallback的解决方法

简介: This application has no explicit mapping for /error, so you are seeing this as a fallback的解决方法

背景:使用 springboot + vue 构建的微信点餐系统

一、错误提示

最近在做一个项目,配置完信息以后,一直报错,访问URL报错信息如下:

3.png

Whitelabel Error Page

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

Sun Jun 23 13:26:10 CST 2019

There was an unexpected error (type=Not Found, status=404).

No message available


二、错误原因

2.1 原因一:启动类的位置不对

Springboot项目启动类的位置不对。要将启动类放在最外侧,即包含所有子包。(spring-boot会自动加载启动类所在包下及其子包下的所有组件)

4.png

2.2 原因二:控制器的URL路径书写问题  

控制器的URL路径书写问题  

@RequestMapping(“/xxx”)  

实际访问的路径与"xxx"不符合。

2.3 原因三:配置文件中视图解析器的配置问题

在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

三、解决方案

注意此项目引入的Spring Boot 版本是2.1.5的,然后项目的配置文件(application.yml)信息如下:

spring:  datasource:    driver-class-name: com.mysql.jdbc.Driver
    username: root
    password: 123456    url: jdbc:mysql://192.168.31.204/sell?characterEncoding=utf-8&useSSL=false
  jpa:    show-sql: trueserver:  context-path: /sell

上网查了很多,原因是SpringBoot启动类(main方法所在的类)未放在根目录下,导致@SpringBootApplication扫描不全所有包。

3.1 解决方案一

针对原因一的解决方案,也是官网上建议的:将SpringBoot启动类(main方法所在的类)即Application.java放置在和Controller同级目录,如下图所示。

官网那边说明是,程序只加载Application.java所在包及其子包下的内容。

5.png

3.2 解决方案二

针对原因二,在浏览器中输入的路径与项目中写的路径要一致,如下图所示:

6.png

而我所遇到的还不是因为这个原因,因为我的包目录结构是正确的。我的项目出现WhitePage的原因竟然是spring-boot配置文件(application.yml)中server.context-path不起作用。不起作用的原因也已经查明:server.context-path的配置方式是SpringBoot 1.x.x版本中出现的,而我引用是2.x.x版本的,需要更改为server: servlet: context-path: /sell,/sell是访问的URL中用到的,以后再详细说明。其实归根结底还是访问的路径不存在的原因。

3.3 解决方案三

针对原因三,解决方案已经写在原因说明里了,直接按照说明修改即可。

springboot 在未配置访问静态资源的情况下,会默认到 templates 文件夹下找index页面。。我现在还没有配置,后续会继续编写。


关于server.context-path不起作用的详细说明可以点击查看此链接spring-boot配置文件中server.context-path不起作用的解决方案_No8g攻城狮的博客-CSDN博客


Whitelabel Error Page

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

Sun Jun 23 13:26:10 CST 2019

There was an unexpected error (type=Not Found, status=404).

No message available


本文首发于CSDN,为博主原创文章,如果需要转载,请注明出处,谢谢!


完结!

相关文章
|
2月前
|
XML 缓存 API
【Azure API 管理】使用APIM进行XML内容读取时遇见的诡异错误 Expression evaluation failed. Object reference not set to an instance of an object.
【Azure API 管理】使用APIM进行XML内容读取时遇见的诡异错误 Expression evaluation failed. Object reference not set to an instance of an object.
‘;‘ expected,Missing semicolon.Syntax Missing semicolon multi (web,若依定义方法,修改method,之后在mounted()用this
‘;‘ expected,Missing semicolon.Syntax Missing semicolon multi (web,若依定义方法,修改method,之后在mounted()用this
|
5月前
Error:Execution failed for task ':app:javaPreCompileDebug'. > Annotation processors must be explicit
Error:Execution failed for task ':app:javaPreCompileDebug'. > Annotation processors must be explicit
87 0
|
10月前
|
小程序 前端开发 PHP
laravel8(一)Target class [XXXXXController] does not exist.错误的解决办法
Laravel 8配置好路由后,访问提示: arduino 复制代码 Target class [XXXXXController] does not exist. 错误。 出现这个错误的原因是Laravel8对路由命名空间做出了更新(详见:路由命名空间更新),而我们仍然在使用Laravel6或者7版本的方式写路由。 Laravel 8路由配置方式: php 复制代码 use App\Http\Controllers\UserController; Route::get('/users', [UserController::class, 'index']); Laravel 6/7路由配置方
127 1
|
Java 编译器 Spring
报错:No fallback instance of type class**解决办法
报错:No fallback instance of type class**解决办法
999 0
报错:No fallback instance of type class**解决办法
|
Java Android开发
Bad method handle type 7异常解决
在利用androidx版本写demo时,在添加了一些依赖后,遇到了`java.lang.ClassNotFoundException`bug,这就很奇怪了,我就添加rxjava3的依赖,就给我报这个错误。
|
Java 数据库 Android开发
Eclipse中出现Syntax error on token "class", invalid VariableDeclarator(关键字问题)
Eclipse中出现Syntax error on token "class", invalid VariableDeclarator(关键字问题)
149 0
Eclipse中出现Syntax error on token "class", invalid VariableDeclarator(关键字问题)
Unknown run configuration type AndroidRunConfigurationType的解决办法
Unknown run configuration type AndroidRunConfigurationType的解决办法
103 0
|
Web App开发 API C#
Pywinauto 应用后端类型选择错误:AttributeError: ‘NoneType‘ object has no attribute ‘backend‘. 原因及解决办法
Pywinauto 应用后端类型选择错误:AttributeError: ‘NoneType‘ object has no attribute ‘backend‘. 原因及解决办法
364 0
Pywinauto 应用后端类型选择错误:AttributeError: ‘NoneType‘ object has no attribute ‘backend‘. 原因及解决办法
|
Java 应用服务中间件 Android开发
Struts2 Error filterStart异常的解决方法总结
今天一位网友让polaris帮忙解决一些jqGrid的问题。在polaris部署运行其工程时,却抛出Struts2 Error filterStart异常,也就是根本连tomcat都启动不了。
199 0