package cn.com.app.base.exception;
import cn.com.app.base.dto.SystemExceptionMsgDto;
import cn.com.app.base.service.SystemExcepWxWarnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* 全局校验异常处理
* ClassName: GlobalExceptionHandler
* Function:
* Date: 2020年6月4日 下午1:59:14
*/
@RestControllerAdvice
public class GlobalExceptionHandler {
@Autowired
private SystemExcepWxWarnService systemExcepWxWarnService;
@ExceptionHandler(Exception.class)
public void handleException(Exception e) {
BUSILOGGER.info("系统异常--------->",e);
// 发送企业微信预警
SystemExceptionMsgDto systemExceptionMsgDto = SystemExceptionMsgDto.builder()
.exceptionDesc(e.getMessage())
.exception(e)
.build();
systemExcepWxWarnService.sendWxMessage(systemExceptionMsgDto);
}
}
全局异常处理
于 2023-08-22 20:10:34 首次发布
该文章介绍了在Spring框架中使用@RestControllerAdvice实现的全局异常处理策略,捕获所有异常并记录日志,同时通过Autowired注入SystemExcepWxWarnService来发送企业微信预警通知。
4万+

被折叠的 条评论
为什么被折叠?



