【问题标题】:springboot swagger3 "Failed to load remote configuration."spring boot swagger 3“无法加载远程配置。”
【发布时间】:2022-03-30 03:01:17
【问题描述】:

带有 Springdoc 的 Spring Boot 2.6.3。

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.6.5</version>
        </dependency>

applicaton.yaml 中,当我将路径设置为/v3/api-docs 或将其删除时,这意味着使用默认路径“/v3/api-docs”。 Swagger UI 页面使用 API 正确显示 http://localhost:8080/swagger-ui/index.html

但我想覆盖如下路径

  api-docs.path: /bus/v3/api-docs

然后 Swagger UI 显示“Failed to load remote configuration”错误:

【问题讨论】:

    标签: spring-boot swagger-ui springdoc springdoc-openapi-ui


    【解决方案1】:

    如果您在应用程序中使用 Spring Security,则必须在配置中包含 URL。 请将以下代码添加到您的项目中。

    @Configuration
    public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
        @Override
        public void configure(WebSecurity web) throws Exception {
            web.ignoring().antMatchers("/swagger-ui/**", "/bus/v3/api-docs/**");
        }
    }
    

    【讨论】:

    • 如果您最近更新,您可能忽略了v2,但没有忽略v3
    【解决方案2】:

    在您的浏览器中执行“清空缓存和硬刷新”。

    【讨论】:

      【解决方案3】:
      Make sure to add "/v3/api-docs/**" in configure method.
      @Configuration
      public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
          @Override
          public void configure(WebSecurity web) throws Exception {
              web.ignoring().antMatchers("/swagger-ui/**", "
      /v3/api-docs/**");
          }
      }
      

      【讨论】:

      • 您的答案与 Amir Pezeshk 的答案有何不同?
      【解决方案4】:

      我遇到了同样的问题,解决方法是在 application.yml 中添加以下属性

      server:
        forward-headers-strategy: framework
      

      由于以下原因需要这样做

      Swagger 依靠内部路由从客户端的角度发出请求。将服务放在反向代理后面而不提供 X-Forwarded 标头将导致用户无法按预期使用文档

      来源 -> https://medium.com/swlh/swagger-spring-boot-2-with-a-reverse-proxy-in-docker-8a8795aa3da4

      【讨论】:

        【解决方案5】:

        我想我已经解决了这个问题(感谢@Ivan Zaitsev),只是想为答案添加更多说明。

        我也更改了 api-docs.path 属性,我也遇到了同样的问题。当我检查 swagger UI 页面上的请求时,swagger-config 请求返回 404,因为它仍在尝试从旧 URL 获取配置。

        即使我更改了 api-docs.path 属性,这里还是尝试检索 swagger-config 的请求 URL。 http://localhost:8080/api/v3/api-docs/swagger-config

        原来是openapi-ui相关的问题,因为我在清除浏览器缓存和cookies的时候能够解决。最好使用隐身浏览器进行测试,因为它不保存会话中的任何数据。

        【讨论】:

          猜你喜欢
          • 2018-02-12
          • 1970-01-01
          • 1970-01-01
          • 2021-10-02
          • 2017-10-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-12-23
          相关资源
          最近更新 更多