还是常规的原因,日常开发中的小细节记录,本次主要是简单描述一下在spring下对于全局异常的处理方案,网上也有各种各样的方案,有很优雅的,也有很直接的。
我本次项目的框架体系大致就是springboot的一套直接贴代码:
package com.utils;
import com.sun.corba.se.impl.io.TypeMismatchException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.ConversionNotSupportedException;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.web.HttpMediaTypeNotAcceptableException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
/**
* @title: 全局异常处理
* @author yanwei.shen
* @projectName zeus-service
* @description: TODO
* @date 2019/11/2018:56
*/
@ControllerAdvice
public class ZeusExceptionHandler {
private static final Logger logger = LoggerFactory.getLogger(ZeusExceptionHandler.class);
//空指针的异常
@ExceptionHandler(NullPointer