Spring Boot 3的springdoc-openapi-ui不工作
我想把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错误。
我错过了什么呢?
根据该文件:
For spring-boot 3 support, make sure you use springdoc-openapi 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
请注意,模块已经被重新命名了。
我完全同意@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。
对我来说,这很有帮助,只是改变了依赖关系
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>
'springdoc-openapi-starter-webmvc-ui'不能与 "spring-boot-starter-webflux"一起使用,除非你包含 "spring-boot-starter-web"。 如果你包含spring security,那么它就失效了。