猿小白888 2022-09-08 18:59 采纳率: 25%
浏览 42
已结题

关于#springboot#集成security+jwt的问题,如何解决?

springboot项目集成spring security+jwt
每次运行时抛出自定义异常时都会报空指针

img

/**
* 自定义异常
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommonException extends RuntimeException {
    private int code;
    private String msg;

    public CommonException(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMessage();
    }
}
/**
* 自定义捕获
*/
@RestControllerAdvice
public class CommonExceptionHandler {

    public static final Logger logger = LoggerFactory.getLogger(CommonExceptionHandler.class);

    /**
     * 全局异常捕捉处理
     * @param ex
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    public R errorHandler(HttpServletRequest req, Exception ex) {
        logger.error(String.format("发生未处理的异常={%s},url={%s},params={%s}",
                ex.getMessage(),req.getRequestURL(),req.getParameterMap().toString()),ex);
        return R.fail(100,ex.getMessage());
    }

    /**
     * 拦截捕捉自定义异常 CommonException.class
     * @param ex
     * @return
     */
    @ExceptionHandler(value = CommonException.class)
    public Map myErrorHandler(HttpServletRequest req, CommonException ex) {
        Map map = new HashMap();
        map.put("code", ex.getCode());
        map.put("msg", ex.getMsg());
        return map;
    }
}
/**
* 使用
*/
throw new CommonException(401, "token失效,请重新登录");
  • 写回答

1条回答 默认 最新

  • 鱼找水需要时间 Java领域优质创作者 2022-09-08 19:07
    关注

    过滤器点进去定位到63行,这里报空指针,看是否使用对象属性,对象应该为null

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 9月19日
  • 创建了问题 9月8日

悬赏问题

  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块
  • ¥15 nhanes加权logistic回归,svyglm函数