springboot整合swagger的问题收集 【测试通过】

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的启动注解,不启动权限验证,也可以解决

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值