请求swagger报错:nested exception is java.lang.NullPointerException] with root cause
问题:
请求swagger(localhost:8089/swagger-ui.html)报错:
Servlet.service() for servlet [dispatcherServlet] in context with path [/qzcsbj] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
原因:
被拦截器拦截了
解决:
自定义的RequestInterceptor拦截器中,preHandle方法下加入:
String requestURI = request.getRequestURI(); if(requestURI.contains(".ico")||requestURI.contains("swagger")||requestURI.contains(".css")||requestURI.endsWith(".js")||requestURI.contains(".png")||requestURI.contains("/v2/api-docs")){ System.out.println(":~~~~~~~~~~~~~~~~~~~~~~~~~~~~拦截器中直接放行,不校验权限:" + requestURI); return true; }
补充:通过过滤器,可以发现,请求swagger实际会发以下请求
==================过滤器中直接放行:/swagger-ui.html ==================过滤器中直接放行:/webjars/springfox-swagger-ui/css/reset.css ==================过滤器中直接放行:/webjars/springfox-swagger-ui/css/typography.css ==================过滤器中直接放行:/webjars/springfox-swagger-ui/css/screen.css ==================过滤器中直接放行:/webjars/springfox-swagger-ui/lib/object-assign-pollyfill.js ==================过滤器中直接放行:/webjars/springfox-swagger-ui/lib/jquery-1.8.0.min.js ==================过滤器中直接放行:/webjars/springfox-swagger-ui/lib/jquery.slideto.min.js ==================过滤器中直接放行:/webjars/springfox-swagger-ui/lib/jquery.wiggle.min.js ==================过滤器中直接放行:/webjars/springfox-swagger-ui/lib/jquery.ba-bbq.min.js ==================过滤器中直接放行:/webjars/springfox-swagger-ui/lib/lodash.min.js ==================过滤器中直接放行:/webjars/springfox-swagger-ui/lib/handlebars-4.0.5.js ==================过滤器中直接放行:/webjars/springfox-swagger-ui/lib/backbone-min.js ==================过滤器中直接放行:/webjars/springfox-swagger-ui/swagger-ui.min.js ==================过滤器中直接放行:/webjars/springfox-swagger-ui/lib/highlight.9.1.0.pack.js ==================过滤器中直接放行:/webjars/springfox-swagger-ui/lib/highlight.9.1.0.pack_extended.js ==================过滤器中直接放行:/webjars/springfox-swagger-ui/lib/jsoneditor.min.js ==================过滤器中直接放行:/webjars/springfox-swagger-ui/lib/marked.js ==================过滤器中直接放行:/webjars/springfox-swagger-ui/lib/swagger-oauth.js ==================过滤器中直接放行:/webjars/springfox-swagger-ui/springfox.js ==================过滤器中直接放行:/webjars/springfox-swagger-ui/images/logo_small.png ==================过滤器中直接放行:/webjars/springfox-swagger-ui/css/print.css ==================过滤器中直接放行:/swagger-resources/configuration/ui ==================过滤器中直接放行:/webjars/springfox-swagger-ui/images/favicon-32x32.png ==================过滤器中直接放行:/swagger-resources ==================过滤器中直接放行:/v2/api-docs ==================过滤器中直接放行:/swagger-resources/configuration/security ==================过滤器中直接放行:/webjars/springfox-swagger-ui/css/typography.css ==================过滤器中直接放行:/swagger-resources/configuration/ui ==================过滤器中直接放行:/swagger-resources ==================过滤器中直接放行:/swagger-resources/configuration/security ==================过滤器中直接放行:/webjars/springfox-swagger-ui/images/throbber.gif
原文已更新:https://www.cnblogs.com/uncleyong/p/17139382.html
__EOF__
本文作者:持之以恒(韧)
关于博主:擅长性能、全链路、自动化、企业级自动化持续集成(DevTestOps)、测开等
面试必备:项目实战(性能、自动化)、简历笔试,https://www.cnblogs.com/uncleyong/p/15777706.html
测试提升:从测试小白到高级测试修炼之路,https://www.cnblogs.com/uncleyong/p/10530261.html
欢迎分享:如果您觉得文章对您有帮助,欢迎转载、分享,也可以点击文章右下角【推荐】一下!
关于博主:擅长性能、全链路、自动化、企业级自动化持续集成(DevTestOps)、测开等
面试必备:项目实战(性能、自动化)、简历笔试,https://www.cnblogs.com/uncleyong/p/15777706.html
测试提升:从测试小白到高级测试修炼之路,https://www.cnblogs.com/uncleyong/p/10530261.html
欢迎分享:如果您觉得文章对您有帮助,欢迎转载、分享,也可以点击文章右下角【推荐】一下!