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 ...
随机推荐
- dbt 基本试用
dbt 是一个很不错的进行etl 中的t 处理的工具,灵活简单,我们需要写的就是select 语句 dbt 帮助我们进行处理 测试集成了graphql 以及使用docker 运行 安装 pip ins ...
- 百度,谷歌,360,搜狗,神马等蜘蛛IP段
https://www.imydl.com/wzjs/5971.html 记得3月份的时候明月分享过一篇[站长必备:百度.谷歌.搜狗.360等蜘蛛常见IP地址]的文章,好像一直都受到了众多站长们的关注 ...
- 使用fiddler进行genymotion安卓虚拟机手机抓包
1.首先先下载fiddler,这个直接百度就有啦. 2.打开fiddler ,可以看到这个界面还是挺帅的: 3.选择Tools - Fiddler Options -Https选项卡将配置设置为如下: ...
- SQLServer2008开启远程连接
1.查看sqlserver brower协议是否启动 2.对象资源管理器 右键属性->选择-> 方面->服务器配置->Remoteaccess ->True 3.对象资源 ...
- jmeter ---模拟发送TCP/UDP/HTTP/FTP等请求包
JMeter安装UDP插件后支持发送UDP协议的请求包,官方介绍安装插件后可以用来测试DNS, NTP, TFTP, Boot servers and many-many other systems. ...
- yii framework config 可以被配置的项目
http://hi.baidu.com/lossless1009/item/990fdb33a52ffcf1e7bb7a4c <?php002 003 // 取消下行的注释,来定义一个路径别名0 ...
- BASIC-13_蓝桥杯_数列排序
示例代码: #include <stdio.h>#include <stdlib.h> int main(void){ int n = 0 ; int i = 0 , j = ...
- Oracle学习操作(7)用户、权限、角色
一.oracle用户: 二.权限 1.系统权限: sys登陆创建c##test用户后,给用户c##test授权,并且带有传播性: SQL> create user c##test identif ...
- 接口测试3-2csv格式
csv文件数据 IntellJ IDEA打开终端:view-tool windows-terminal,可以在终端中查看文件路径 阿里 马云 京东 刘强东 京东 马化腾 #java //读取csv文件 ...
- 如何将JQUERY对象转成Javascript对象
问: <div id="test"></div> $("#test") //由Javascript对象转为Jquery对象: 但是如何转 ...