我正在使用 Spring Boot 3 和库
springdoc-openapi-starter-webmvc-ui
来获取 swagger 文档。当从现有控制器读取数据时,swagger ui 工作正常 http://localhost:8080/swagger-ui/index.html
。我当前的依赖项如下 -
<!-- Swagger dependency-->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>0.45</version>
</dependency>
但现在我尝试使用自定义 yaml 文件,其中定义了 openapi 规范。为此,我在我的
application.properties
文件中添加了以下内容
springdoc.api-docs.path=classpath:/swagger-config.yaml
再次运行服务器时,相同的 swagger 链接会出现以下错误
Failed to load remote configuration.
我尝试了各种其他配置,但似乎没有一个能够从
swagger-config.yaml
文件中获取规格。这里的任何输入都会非常有帮助!!!
请注意,我的
swagger-config.yaml
是一个有效文件,它在在线 swagger editor 中工作得很好。
您要设置的属性是
springdoc.swagger-ui.url
而不是 springdoc.api-docs.path
。
springdoc.swagger-ui.url=/swagger-config.yml
应该可以解决问题。
另外,请注意,YML 文件应放在
src/main/resources/static
目录中。
将此添加到 application.xml server.forward-headers-strategy=框架