Swagger| Unable to infer base url. This is common when using dynamic servlet registration...

  • 问题描述:
    Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually:
    Swagger| Unable to infer base url. This is common when using dynamic servlet registration..._第1张图片

  • 分析原因-解决办法
    问题大概描述的是无法推断出基础的URL路径,出现这个问题的原因有很多种,可以从以下几个方面着手来排序问题:
    1.确认是否已经开启了EnableSwagger2
    Swagger| Unable to infer base url. This is common when using dynamic servlet registration..._第2张图片
    2.确保swagger的静态资源和动态资源能正常访问
    可以参考Swagger URL检查指南来测试资源是否可以访问,如果资源不能访问,可以从资源是否被屏蔽,是否被权限机制挡住来排查,最后放行这行URL资源路径既可:
    需要放行的资源URL如下:
    Swagger| Unable to infer base url. This is common when using dynamic servlet registration..._第3张图片
    在Servlet中做静态资源映射可以做如下设置:
    在这里插入图片描述

参考资料:
https://www.iteye.com/blog/wwwcomy-2425915
https://stackoverflow.com/questions/47425048/why-does-springfox-swagger2-ui-tell-me-unable-to-infer-base-url
http://www.kstrive.com/2018/01/06/spring-mvc集成swagger空白页面/

你可能感兴趣的:(【Swagger】)