描述:首先自定义了一个运行中的异常,写逻辑时运行时报错正常,另外再写用户认证jwt时,又自定义了一个异常继承exception但是操作时发现并没有走到这里。不管怎么测试都没有效果。
解决办法:在ExceptionHandler类增加@ExceptionHandler,因为我第一次写java项目,基础稍微弱一点,不太明白为什么。所以解释不清楚
package com.shouchuang.exception;
import com.shouchuang.utils.JSONResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseBody;
@ControllerAdvice//增加后解决了
public class ExceptionHandler {
@ResponseBody
@org.springframework.web.bind.annotation.ExceptionHandler(MyCustomException.class)
public JSONResult returnMyCustomException(MyCustomException e)
{
return JSONResult.errorMsg(e.getMessage());
}
//
@ResponseBody
@org.springframework.web.bind.annotation.ExceptionHandler(MyBaseException.class)
public JSONResult returnBaseException(MyBaseException e)
{
System.out.println("到这粱");
return JSONResult.errorMsg(e.getMessage());
}
}



