报错信息如下:
Failed
to invoke @ExceptionHandler method: public com.alibaba.fastjson.JSONObject com.*.error.ErrorIntercept.handlexExcption(java.lang.Exception,org.springframework.web.method.HandlerMethod)
全局异常处理器
package com.data.docking.exception;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import com.data.docking.tools.ApiCodeEnum;
import com.data.docking.tools.JsonApi;
/**
* @description: 全局异常处理器
*/
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@ExceptionHandler(Exception.class)
public JsonApi defaultErrorHandler(Exception e) {
e.printStackTrace();
log.error("error msg:{}", e.getMessage());
return new JsonApi(ApiCodeEnum.ERROR).setMsg(e.getMessage());
}
}
将
@ExceptionHandler(Exception.class) 改成 @ExceptionHandler(BindException.class)就可以了。