Springboot项目自定义异常全局处理实践

        还是常规的原因,日常开发中的小细节记录,本次主要是简单描述一下在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
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值