springBoot2.x global catch the exception

/**
 * 全局捕获异常
 */
@ControllerAdvice(basePackages = "com.liangjian.controller")//扫包范围
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Map<String, Object> exceptionHandler() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("errorCode", "500");
        map.put("errorMsg " , " System Error! " );
         return Map; 
    } 

}

 

Guess you like

Origin www.cnblogs.com/castlechen/p/11145074.html