SpringBoot集成Swagger2页面无法访问情况

您所在的位置:网站首页 所有网页无法访问 SpringBoot集成Swagger2页面无法访问情况

SpringBoot集成Swagger2页面无法访问情况

2024-07-09 00:31| 来源: 网络整理| 查看: 265

Spring Boot 集成 Swagger2 之后会有访问失败情况,比如: 在这里插入图片描述

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:

翻译出来就是

无法推断基本url。这在使用动态servlet注册或API位于API网关之后时很常见。基本url是提供所有swagger资源的根。例如,如果api在以下位置可用:http://example.org/api/v2/api-docs那么基本url是http://example.org/api/.请手动输入位置:

解决方法,开启Swagger2 第一、在SpringBootApplication启动类上加上@EnableSwagger2注解 在这里插入图片描述

第二、创建一个Swagger的配置类,加上 @Configuration 和 @EnableSwagger2 在这里插入图片描述

基本上来说一般访问失败都是没有开启Swagger导致的。

接下来就是其他过滤器拦截器等等导致的失败问题

问题一: 由于对于返回结果做了统一封装,会通过 @RestControllerAdvice 去访问需要的东西,页面解析不出来,因此访问会出错;

重写 ResponseBodyAdvice 的 supports 方法,对Swagger不进行处理 在这里插入图片描述



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3