全局异常处理

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);
	}

}

你可能感兴趣的:(java,全局异常,统一异常)