Spring Boot 全局异常配置
Spring Boot 全局异常配置,处理异常控制器需要和发生异常的方法在一个类中。使用 ControllerAdvice 注解
package com.li.controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; @Controller
public class ExceptionHandlerController {
@RequestMapping("/exceptionTest")
@ResponseBody
public String test() throws Exception{
System.out.println("测试");
int i=1/0;
return Integer.toString(i);
}
@ControllerAdvice
class HandlerException{
@ExceptionHandler(Exception.class)
@ResponseBody
public String defultExcepitonHandler(Exception e) {
// return "{\"error\":\"error\"}";
return "error";
}
}
}
https://blog.csdn.net/qq_34083066/article/details/79424142
Spring Boot 全局异常配置的更多相关文章
- Spring Boot 全局异常捕获
import javax.servlet.http.HttpServletRequest; import org.springframework.web.bind.annotation.Control ...
- Spring Boot 2.0 配置图文教程
摘要: 原创出处 https://www.bysocket.com 「公众号:泥瓦匠BYSocket 」欢迎关注和转载,保留摘要,谢谢! 本章内容 自定义属性快速入门 外化配置 自动配置 自定义创建 ...
- spring设置全局异常处理器
1.spring设置全局异常,它的原理是向上捕获 spring.xml配置 <!--自定义全局异常处理器--> <bean id="globalExceptionResol ...
- spring boot web相关配置
spring boot集成了servlet容器,当我们在pom文件中增加spring-boot-starter-web的maven依赖时,不做任何web相关的配置便能提供web服务,这还得归于spri ...
- spring boot多数据源配置(mysql,redis,mongodb)实战
使用Spring Boot Starter提升效率 虽然不同的starter实现起来各有差异,但是他们基本上都会使用到两个相同的内容:ConfigurationProperties和AutoConfi ...
- 转-spring boot web相关配置
spring boot web相关配置 80436 spring boot集成了servlet容器,当我们在pom文件中增加spring-boot-starter-web的maven依赖时,不做任何w ...
- 【转】spring boot application.properties 配置参数详情
multipart multipart.enabled 开启上传支持(默认:true) multipart.file-size-threshold: 大于该值的文件会被写到磁盘上 multipart. ...
- 【转】spring boot web相关配置
spring boot集成了servlet容器,当我们在pom文件中增加spring-boot-starter-web的maven依赖时,不做任何web相关的配置便能提供web服务,这还得归于spri ...
- Spring MVC全局异常后返回JSON异常数据
问题: 当前项目是作为手机APP后台支持,使用spring mvc + mybaits + shiro进行开发.后台服务与手机端交互是发送JSON数据.如果后台发生异常,会直接返回异常页面,显示异常内 ...
随机推荐
- Unity3d实现幸运转盘
完成效果 我说一下制作流程,然后再看后面的代码1.创建一个image,选择我们的转盘背景图,素材找我或者网上都有,不多说了哈:2.创建一个空物体,位于转盘的正中心,因为我们的转盘指针的旋转中心是根据空 ...
- #import 无法打开源文件msado.tlh
#import 无法打开源文件msado.tlh #import "c:\program files\common files\system\ado\msado15.dll" no ...
- TCP/IP协议族-----24、网络管理(SNMP)
- Oracle Apex 有用笔记系列 2 - 文件上传管理
1. 页面设计 页面A有若干region, 当中一个region用于文件列表管理(包含显示,下载.删除).如图A. 在页面A有一button,点击它会调用页面B,页面B负责文件上传.如图B. 图A 图 ...
- day23<File类递归练习>
File类递归练习(统计该文件夹大小) File类递归练习(删除该文件夹) File类递归练习(拷贝) File类递归练习(按层级打印) 递归练习(斐波那契数列) 递归练习(1000的阶乘所有零和尾部 ...
- excel中,一系列单元格中包含某一个字段的单元格数量?
excel中,一系列单元格中包含某一个字段的单元格数量?这个怎么写公式?如:A列单元格A1-A7的内容分别为 A.AB.BC.AC.CD.AD.EA,怎么数这一列中几个单元格的内容包含A字母? 任意单 ...
- Linux之expect
一,安装expect yum install expect 其实expect根bash形势上差不多的. 二,实例 1,ssh实现自动登录,并停在登录服务器上 查看复制打印? #!/usr/bin/ex ...
- 说说M451的例程库的说明
Directory Information Document Driver reference manual and reversion history. Library Driv ...
- ubuntu下code::blocks编译运行一个简单的gtk+2.0项目
在具体的操作之前,首先需要安装一些必要的软件.ubuntu下默认安装了gcc,不过缺少必要的Header file,可以在命令行中输入下面的指令安装build-essential套件:sudo apt ...
- zookeeper-端口说明
一.zookeeper有三个端口(可以修改) 1.2181 2.3888 3.2888 二.3个端口的作用 1.2181:对cline端提供服务 2.3888:选举leader使用 3.2888:集群 ...