springBoot全局异常拦截

package com.hzstoa.hzst.main.exception;

import com.hzstoa.hzst.commonweb.entity.ActionResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class ExceptionControllerAdvice {
    @ExceptionHandler(value = Throwable.class)
    public ActionResult handleException(Throwable throwable){
        throwable.printStackTrace();
        log.error(throwable.getMessage());
        return ActionResult.fail("系统未知异常");
    }
}

版权声明:本文为weixin_48921808原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。