Qia*_*gLi 34 java swagger-ui spring-boot springdoc springdoc-openapi-ui
Spring Boot 2.6.3 与 Springdoc。
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.5</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
在 中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
Run Code Online (Sandbox Code Playgroud)
然后 Swagger UI 显示“无法加载远程配置”错误:

小智 39
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/**");
}
}
Run Code Online (Sandbox Code Playgroud)
Kas*_*ios 13
我遇到了同样的问题,如果您位于反向代理后面,解决方法是在 application.yml 中添加以下属性
server:
forward-headers-strategy: framework
Run Code Online (Sandbox Code Playgroud)
由于以下原因需要这样做
Swagger 依赖内部路由从客户端的角度发出请求。将服务置于反向代理后面而不提供 X-Forwarded 标头将导致用户无法按预期使用文档
来源-> https://medium.com/swlh/swagger-spring-boot-2-with-a-reverse-proxy-in-docker-8a8795aa3da4
小智 12
如果您在应用程序中使用 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/**");
}
}
Run Code Online (Sandbox Code Playgroud)
小智 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相关的问题,因为我清除浏览器缓存和cookie后就能够解决了。最好使用隐身浏览器进行测试,因为它不保存会话上的任何数据。
| 归档时间: |
|
| 查看次数: |
53274 次 |
| 最近记录: |