ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

springboot整合swagger的问题收集

2021-03-10 15:01:28  阅读:204  来源: 互联网

标签:http springboot 收集 anon put swagger filterChainDefinitionMap shiro


1 访问swagger首页 http://localhost:8080/swagger-ui.html出错

错误信息如下:

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: 


解决办法
在启动类上加上注解@EnableSwagger2 如果还不行,那就是因为你系统有shiro鉴权导致,解决方案:

1.放开对该页面的鉴权

先把shiro配置类的  @Configuration 给注释掉,再打开 http://localhost:8080/swagger-ui.html 右键 选择检查 或 按F12键,查看该页面的网络请求,在network这项里,通过查看发现访问该页面,需要访问哪些资源,把相应的文件及文件夹在shiro中放开权限,如下:

        filterChainDefinitionMap.put("/swagger-ui.html", "anon");
        filterChainDefinitionMap.put("/swagger-resources", "anon");
        filterChainDefinitionMap.put("/swagger-resources/**", "anon");
        filterChainDefinitionMap.put("/webjars", "anon");
        filterChainDefinitionMap.put("/webjars/**", "anon");
        filterChainDefinitionMap.put("/v2", "anon");
        filterChainDefinitionMap.put("/v2/**", "anon");
加上这些配置后,再把 shiro配置类的  @Configuration 给注释去掉,再打开 http://localhost:8080/swagger-ui.html 访问正常了       
        
2.去掉shiro的启动注解,不启动权限验证,也可以解决

 

标签:http,springboot,收集,anon,put,swagger,filterChainDefinitionMap,shiro
来源: https://blog.csdn.net/huwei2003/article/details/114635257

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有