1、通过intellij idea创建spring boot项目,如下图所示

2、添加maven依赖,如下图所示<dependenc鲻戟缒男y> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>

3、创建一个测试controller方法,然后返回异常,代码如下@RestController@RequestMapping("/test")public class TestController { @RequestMapping("") public Map test(@RequestBody Map map) throws Exception { if (1==1){ throw new Exception("1111111111"); } return map; }}

4、创建全局异常处理器,使用@ControllerAdvice,@ExceptionHandler等注解

5、启动程序,访问rest接口

6、全局异常处理器被执行
