遇一山,过一山,处处有风景;只要勇敢向前,一路尽是繁花盛开。 | (点击查看→)【测试干货】python/java自动化、持续集成、性能、测开、简历、笔试面试等

请求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

 

posted @ 2023-02-20 23:13  全栈测试笔记  阅读(359)  评论(0编辑  收藏  举报
浏览器标题切换
浏览器标题切换end