springBoot异常处理
1.status=404 Whitelabel Error Page
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Mon Nov 13 16:37:27 CST 2017
There was an unexpected error (type=Not Found, status=404).
No message available
刚开始学习,按照别人写的HelloWorld进行配置后,运行报出以上错误,检查Path后没有问题。
最后搜索发现问题出在 @SpringBootApplication的扫描范围:
@SpringBootApplication的同级包及其子包会被扫描,因此Application需要放在整个系统的主路径下。
同时@RequestMapping(value="/listPort",method=RequestMethod.POST)这个也要写对,我将 value变为了name导致一直扫描不到。
同时不用使用项目名: http://127.0.0.1:8080/[annonationPath]
如果要加,则配置文件中添加 server.context-path=/项目名
如果使用thymeleaf的templates,出现错误则注意pom.xml中是否有加入thymeleaf依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2. @SpringBootApplication、SpringApplication、ModelAndView、EmbeddedServletContainerCustomizer多个类无法引入问题
刚开始使用springBoot的2.0.0 M6测试版,但引入有有些类或注解加载不进去(EmbeddedServletContainerCustomizer),可能大版本中有些类注解有变化所致,最后返回到1.5.8当前正式版后,出现以上错误,怎么Maven Update Project 都无法解决。最后网上有人说是jar包冲突导致。
直接删除掉Maven仓库中的org.springFramework,从新更新工程,让从新下载即可。
3. springboot 报错 没有主清单属性
打包成jar文件直接运行报错。缺少主驱动程序,
参照:https://blog.csdn.net/u010429286/article/details/79085212
添加 maven-plugin驱动。
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.jetty.mac.MacJetty.App</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
然后重新
>mvn clean package
>java -jar ****.jar
4.元素类型 "link" 必须由匹配的结束标记 "</link>" 终止
springboot 中引入thymeleaf,但是在页面上<link>没有结束标签,导致。
添加依赖:
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
在application.properties中修改:
spring.thymeleaf.mode=HTML5
->
spring.thymeleaf.mode=LEGACYHTML5
5. static静态文件访问不到404
在配置文件application.properties中添加static的资源访问
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:/static/
6.org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'timestamp' cannot be found on object of type 'java.util.HashMap' - maybe not public?
在上传文件时,前台显示404,后端报错。
对于springboot的404并非一定是404没有找到资源地址,而是出错后不知怎么处理,找不到对应的error page 而报出来的404.
在上传文件时,springboot默认是1Mb的上限。同时如果是自己设置的临时路径,需要设置mkdir,要不然找不到文件路径。以上都有可能抛出此类异常
# file
spring.http.multipart.enabled=true
spring.http.multipart.location=file/tmp
spring.http.multipart.resolve-lazily=false
spring.http.multipart.max-file-size=8Mb
/**
* 临时文件存放地址设置
* @return
*/
@Bean
MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
String location = System.getProperty("user.dir") + "/file/tmp";
File tmpFile = new File(location);
if (!tmpFile.exists()) {
tmpFile.mkdirs();
}
factory.setLocation(location);
return factory.createMultipartConfig();
}
文件上传部分代码:
/**
* 文件读入
*/
@RequestMapping("/file/upload")
@ResponseBody
public RespResult uploadFile(@RequestParam("file")MultipartFile file,Model model) {
7. Caused by: org.xml.sax.SAXParseException: 前言中不允许有内容
springboot+mybatis,运行启动时,注意查看于mybatis相关的配置文件和java文件。如果格式都正确,则需要查看application.properties,因为db的信息就在这里。
@PropertySource(value="classpath:./applicationTest.properties",encoding="UTF-8")
8. SpingBoot:Unregistering JMX-exposed beans on shutdown
原因为:SpringBoot内置Tomcat没有正常启动,在pom.xml 中添加:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
另一种情况是有jar下载失败
参见:https://www.cnblogs.com/QQ931697811/p/6707740.html
9. Failed to start component [StandardEngine[Tomcat]]
因mvn依赖中的tomcat和servlet-api发生冲突导致,需要移除其中一个,或者在依赖中剔除掉Web 依赖。
注意在servelt-api3.0版本后变为 javax.servlet-api.同时在多个项目关联时,有时在项目互相引用时会出现冲突,需要引用jar包解决。即常见的 项目中运行报错,打包后正常。
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
9. AopProxyUtils.getSingletonTarget(Ljava/lang/Object;)Ljava/lang/Object;
springmvc和springboot包之间的冲突,两者只能选择一个。
springBoot异常处理的更多相关文章
- SpringBoot异常处理统一封装我来做-使用篇
SpringBoot异常处理统一封装我来做-使用篇 简介 重复功能我来写.在 SpringBoot 项目里都有全局异常处理以及返回包装等,返回前端是带上succ.code.msg.data等字段.单个 ...
- Springboot异常处理和自定义错误页面
1.异常来源 要处理程序发生的异常,首先需要知道异常来自哪里? 1.前端错误的的请求路径,会使得程序发生4xx错误,最常见的就是404,Springboot默认当发生这种错误的请求路径,pc端响应的页 ...
- SpringBoot异常处理(二)
参数校验机制 JSR-303 Hibernate 参数接收方式: URL路径中的参数 {id} (@PathVariable(name="id") int-whatever) UR ...
- SpringBoot 异常处理
异常处理最佳实践 根据我的工作经历来看,我主要遵循以下几点: 尽量不要在代码中写try...catch.finally把异常吃掉. 异常要尽量直观,防止被他人误解 将异常分为以下几类,业务异常,登录状 ...
- 【使用篇二】SpringBoot异常处理(9)
异常的处理方式有多种: 自定义错误页面 @ExceptionHandler注解 @ControllerAdvice+@ExceptionHandler注解 配置SimpleMappingExcepti ...
- SpringBoot学习15:springboot异常处理方式5(通过实现HandlerExceptionResolver类)
修改异常处理方式4中的全局异常处理controller package com.bjsxt.exception; import org.springframework.context.annotati ...
- SpringBoot学习14:springboot异常处理方式4(使用SimpleMappingExceptionResolver处理异常)
修改异常处理方法3中的全局异常处理Controller即可 package bjsxt.exception; import org.springframework.context.annotation ...
- SpringBoot学习13:springboot异常处理方式3(使用@ControllerAdvice+@ExceptionHandle注解)
问题:使用@ExceptionHandle注解需要在每一个controller代码里面都添加异常处理,会咋成代码冗余 解决方法:新建一个全局异常处理类,添加@ControllerAdvice注解即可 ...
- SpringBoot学习12:springboot异常处理方式2(使用@ExceptionHandle注解)
1.编写controller package com.bjsxt.controller; import org.springframework.stereotype.Controller; impor ...
随机推荐
- Zxing图片拉伸解决 Android 二维码扫描
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/aaawqqq/article/details/24852915 二维码扫描 Android Zx ...
- 【转】每天一个linux命令(20):find命令之exec
原文网址:http://www.cnblogs.com/peida/archive/2012/11/14/2769248.html find是我们很常用的一个Linux命令,但是我们一般查找出来的并不 ...
- shell教程-001:shell简介 什么是shell,shell命令的两种执行方式
Shell本身是一个用C语言编写的程序,它是用户使用Unix/Linux的桥梁,用户的大部分工作都是通过Shell完成的. Shell既是一种命令语言,又是一种程序设计语言.作为命令语言,它交互式地解 ...
- yii2 rbac权限管理学习笔记
下面介绍一个 yii2 的 Rbac 权限管理设置,闲话少说,直接上代码, 1.首先我们要在组件里面配置一下 Rbac ,如下所示(common/config/main-local.php或者main ...
- Dynamics CRM 2011 报表无法显示的问题总结
一.一般打开报表会出现:该报表无法显示.(reProcessingAborted)和由于运行Microsoft SQL Server Reporting Services 的服务器上没有安装 Micr ...
- hosts,No web site is configured at this address.
解决办法: IIS管理器->右击网站->属性->网站——>IP地址一项->选择全部未分配-> 确定关闭 问题解决.
- MySQL数据库函数
一:字符串函数: 1.concat(); concat(S1,S2,S3,......Sn); 把传入参数链接 成一个字符串; 2.insert(); insert(str,x,y,insert); ...
- BASIC-2_蓝桥杯_01字串
问题描述 对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能.它们的前几个是: 请按从小到大的顺序输出这32种01串. 输入格式 本试题没有输入. 输出格式 输出32行,按从小到大的顺 ...
- [转]关闭WIN7“程序兼容性助理”
转载自 http://www.flighty.cn/html/tutorial/20140717_244.html WIN7程序兼容性助理其实是一个非常鸡肋的功能,对于我们基本上可以说没有什么用处,反 ...
- 安卓手机安装虚拟定位的方法Xposed安装器+模拟位置(Xposed模块)
原文:https://www.52pojie.cn/thread-571328-1-1.html 未测试,据说只支持某些手机,小米和华为很难安装,建议买其他品牌. Xposed安装器步骤:·ROOT你 ...