Spring Boot 3的springdoc-openapi-ui不工作

回答 4 浏览 3929 2022-12-06

我想把swagger-ui(OpenAPI 3.0)添加到Spring Boot v3应用程序中。

我已经添加了openapi-ui的maven依赖,它应该能按照文档的要求工作。

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

但显然,它仍然不能工作,localhost:8080/swagger-ui.html返回一个404错误。

我错过了什么呢?

enter image description here

Nadar 提问于2022-12-06
4 个回答
#1楼 已采纳
得票数 18

根据该文件:

For spring-boot 3 support, make sure you use springdoc-openapi v2

https://springdoc.org/v2/

For the integration between spring-boot and swagger-ui, add the library to the list of your project dependencies (No additional configuration is needed)

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.0.0</version>
</dependency>

This will automatically deploy swagger-ui to a spring-boot application:

Documentation will be available in HTML format, using the official swagger-ui jars

The Swagger UI page will then be available at http://server:port/context-path/swagger-ui.html and the OpenAPI description will be available at the following url for json format: http://server:port/context-path/v3/api-docs

server: The server name or IP

port: The server port

context-path: The context path of the application

Documentation can be available in yaml format as well, on the following path : /v3/api-docs.yaml

请注意,模块已经被重新命名了。

https://springdoc.org/v2/#migrating-from-springdoc-v1

enter image description here

JCompetence 提问于2022-12-06
nakhodkin 修改于2022-12-26
#2楼
得票数 4

我完全同意@JCompetence的观点。请注意,springdoc-openapi-ui现在改为springdoc-openapi-starter-webmvc-ui从spring boot 3开始。

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.0.2</version>
</dependency>

请试试这个。如果你想找到更多信息,请查看官方链接:https://springdoc.org/v2/#features

Suman Maity 提问于2022-12-23
nakhodkin 修改于2022-12-25
#3楼
得票数 2

对我来说,这很有帮助,只是改变了依赖关系

   implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.11'

    implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.0.0'

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.0.0</version>
</dependency>
Alexandr Guravskiy 提问于2022-12-14
nakhodkin 修改于2022-12-26
#4楼
得票数 0

'springdoc-openapi-starter-webmvc-ui'不能与 "spring-boot-starter-webflux"一起使用,除非你包含 "spring-boot-starter-web"。 如果你包含spring security,那么它就失效了。

Anchal Todariya 提问于2023-01-18