【问题标题】:Swagger url is not working after migration from springfox swagger to openAPI从 springfox swagger 迁移到 openAPI 后,Swagger url 不起作用
【发布时间】:2021-05-21 11:36:52
【问题描述】:

我有 springfox swagger2,其中 http://localhost:8080/context/swagger-ui.html 工作正常。 现在我已经修改了所有的更改,使其成为 open-api 可运行的。
使用:Migrating from springfox swagger2 to springdoc openapi

现在我可以使用如下组名打开我的服务定义 json:

http://localhost:8080/context-path/v3/api-docs/groupName

但无法像之前使用 springfox 2.0 那样打开 swagger-ui.html

您能帮我吗,如何打开以及网址应该是什么?
当我输入 http://localhost:8080/context/swagger-ui.html 时,它正在创建如下所示的新路由并且没有打开任何内容,404 错误。

http://localhost:8080/context/swagger-ui/index.html?configUrl=/context/v3/api-docs/swagger-config

请注意,我已经在我的项目中添加了 swagger-ui.html,因为它已经为 swagger 2.0 添加了

public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("swagger-ui.html")
      .addResourceLocations("classpath:/META-INF/resources/");

    registry.addResourceHandler("/webjars/**")
      .addResourceLocations("classpath:/META-INF/resources/webjars/");

请帮忙弄个swagger主屏幕,这样我就可以测试休息服务了

【问题讨论】:

  • 请帮助.......

标签: spring-mvc swagger-ui swagger-2.0 springdoc springdoc-openapi-ui


【解决方案1】:

问题是 Swagger-UI 暴露在 http://localhost:8080/swagger-ui.html

如果您希望 Swagger-UI 位于上下文根目录下,请更新 application.properties 文件中的以下属性或其等效项。

springdoc.swagger-ui.path=/your-context-path/swagger-ui.html

属性列表可以找到here

【讨论】:

    猜你喜欢
    • 2020-04-05
    • 2022-01-01
    • 2022-12-08
    • 1970-01-01
    • 2020-02-25
    • 1970-01-01
    • 2019-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多