您当前的位置: 首页 >  http

Dongguo丶

暂无认证

  • 2浏览

    0关注

    472博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

ResourceHttpRequestHandler cannot be cast to HandlerMethod

Dongguo丶 发布时间:2021-07-07 08:35:47 ,浏览量:2

报错: java.lang.ClassCastException: org.springframework.web.servlet.resource.ResourceHttpRequestHandler cannot be cast to org.springframework.web.method.HandlerMethod

在这里插入图片描述

原因就在于,Spring boot 2.0对静态资源也进行了拦截,当拦截器拦截到请求之后,但controller里并没有对应的请求时,该请求会被当成是对静态资源的请求。此时的handler就是 ResourceHttpRequestHandler,就会抛出上述错误。

解决办法就是,在拦截器那里排除静态资源的请求路径

在这里插入图片描述

然后再preHandler报错那里加上 instanceof关键字进行判断。

在这里插入图片描述

关注
打赏
1638062488
查看更多评论
立即登录/注册

微信扫码登录

0.0912s