如何通过使用springdoc-openapi-webflux-ui显示应用程序API文档? [英] How to display app API documentation by using springdoc-openapi-webflux-ui?

查看:1305
本文介绍了如何通过使用springdoc-openapi-webflux-ui显示应用程序API文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了此 https://springdoc.github.io/springdoc-openapi-demos/文档以使用springdoc-openapi-webflux-ui.正如文档所述,我只是将springdoc-openapi-webflux-ui库添加到了我的应用中:implementation('org.springdoc:springdoc-openapi-webflux-ui:1.2.26')

I read this https://springdoc.github.io/springdoc-openapi-demos/ documentation to use springdoc-openapi-webflux-ui. As documentation said I just added springdoc-openapi-webflux-ui library to my app: implementation('org.springdoc:springdoc-openapi-webflux-ui:1.2.26')

此外,我在application.yml中自定义了API的路径:

Additionally, I customized path to API in application.yml:

springdoc:
  swagger-ui:
    path: /swagger-ui.html

启动应用程序后,转到 http://localhost:8080/swagger-ui.html ,它将我重定向到 http://localhost:8080/webjars/swagger-ui/index.html?configUrl =/v3/api-docs/swagger-config .在该页面中,出现错误:

When I start app, and go to http://localhost:8080/swagger-ui.html, it redirects me to http://localhost:8080/webjars/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config. In that page, I got an error:

Whitelabel Error Page
This application has no configured error view, so you are seeing this as a fallback.
Mon Jan 20 05:16:10 UTC 2020
[7192d9dc] There was an unexpected error (type=Not Found, status=404).
No matching handler

问题是:我应该在我的应用程序中添加其他配置以显示API文档吗?

Question is: Should I add additional configurations to my app to show API documentation?

PS:我使用spring.boot 2.2.2:RELEASE

PS: I use spring.boot 2.2.2:RELEASE

推荐答案

默认情况下,您只需要添加springdoc-openapi-webflux-ui的依赖项即可.

By default, you just need to add the dependency of the springdoc-openapi-webflux-ui.

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

您可以看一下演示代码:

You can have a look at the demos code:

您可以检查类路径,然后尝试从IDE外部运行应用程序. 确保您具有正确的IDE设置,具体取决于您的构建工具:

You can check you classpath, and try to run the application from outside the IDE. Make sure you have the correct settings of your IDE depending on your build Tools:

此外,请检查您是否正在使用@EnableWebFlux.

Also, please check if you are using @EnableWebFlux.

如Spring Boot参考文档中所述,当您使用@EnableWebFlux时,您告诉Spring Boot您希望完全控制WebFlux配置并为此禁用所有自动配置(包括静态资源):

As stated in the Spring Boot reference documentation, when you use @EnableWebFlux, you tell Spring Boot that you wish to take full control over the WebFlux configuration and disable all auto-configuration for this (including static resources):

您有两种解决方案:

  1. 删除@EnableWebFlux
  2. 如果您真的想控制Bean的创建,并且绝对要使用@EnableWebFlux,则需要添加WebFluxConfigurer的实现.

对此已在此处进行了讨论:

This has been discussed here:

这篇关于如何通过使用springdoc-openapi-webflux-ui显示应用程序API文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆