Nad*_*dar 86 java spring swagger-ui spring-boot
我正在尝试将 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>
Run Code Online (Sandbox Code Playgroud)
但显然,它仍然不起作用,并且 localhost:8080/swagger-ui.html 返回 404 错误。
我缺少什么?
Sus*_*afa 129
根据文档:
对于spring-boot 3支持,请确保使用springdoc-openapi v2
springdoc-openapi 与 spring-boot 的兼容性矩阵是怎样的?
对于 spring-boot 和 swagger-ui 之间的集成,请将库添加到项目依赖项列表中(无需额外配置)
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
这将自动将 swagger-ui 部署到 spring-boot 应用程序:
文档将以 HTML 格式提供,使用官方 swagger-ui jar
然后,Swagger UI 页面将在以下位置提供,
http://server:port/context-path/swagger-ui.html并且 OpenAPI 描述将在以下 json 格式的 url 中提供: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
Run Code Online (Sandbox Code Playgroud)
https://springdoc.org/#migration-from-springdoc-v1
小智 21
我完全同意@JCompetence 的观点。请注意, springdoc-openapi-ui现在 从 spring boot 3更改为springdoc-openapi-starter-webmvc-ui 。
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
请尝试这个。如果您想了解更多信息,请查看官方链接: https ://springdoc.org/v2/#features
小智 11
对我来说它有帮助,只是改变了依赖关系
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.11'
Run Code Online (Sandbox Code Playgroud)
到
implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.0.0'
Run Code Online (Sandbox Code Playgroud)
或者
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.11'
Run Code Online (Sandbox Code Playgroud)
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.4</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
对于 kotlin 你必须再添加一个依赖项
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
然后在你的主类上添加`@OpenAPIDefinition
@SpringBootApplication
@OpenAPIDefinition
class MyApplication {
}
Run Code Online (Sandbox Code Playgroud)
小智 6
springdoc-openapi-starter-webmvc-uispring-boot-starter-webflux
除非您包含 ,否则无法使用spring-boot-starter-web。如果你包括了 Spring Security 那么它就死了。
| 归档时间: |
|
| 查看次数: |
85649 次 |
| 最近记录: |