Spring Boot 3.x 整合Swagger的示例教程
更新时间:2025年06月17日 10:20:42 作者:AD钙奶-lalala
本文给大家介绍Spring Boot 3.x 整合Swagger的示例教程,结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧
解决Springfox 依赖注入失败问题:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'apiDocumentationScanner' defined in URL ···
最佳方案是放弃 Springfox 2.x,改用 SpringDoc OpenAPI,因为:
Springfox 2.x 已停止维护
Springfox 3.x 对 Spring Boot 支持有限
SpringDoc 是当前最活跃的 Spring API 文档项目
第一步:添加依赖:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.5.0</version>
</dependency>第二步:添加配置:
@Configuration
public class SwaggerConfig {
@Bean
public OpenAPI springShopOpenAPI() {
return new OpenAPI()
.info(new Info()
.title("Spring Boot 中使用 Swagger UI 构建 RESTful API")
.contact(new Contact())
.description("Sun提供的 RESTful API")
.version("v1.0.0")
.license(new License().name("Apache 2.0")
.url("http://springdoc.org")))
.externalDocs(new ExternalDocumentation()
.description("外部文档")
.url("https://springshop.wiki.github.org/docs"));
}
}application.properties配置:
springdoc.api-docs.path=/v3/api-docs springdoc.api-docs.enabled=true springdoc.swagger-ui.path=/swagger-ui.html springdoc.swagger-ui.enabled=true
第三步:访问:
http://localhost:8080/swagger-ui.html
到此这篇关于Spring Boot 3.x 整合Swagger教程的文章就介绍到这了,更多相关Spring Boot 3.x 整合Swagger内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
您可能感兴趣的文章:
- SpringBoot3.1.2 引入Swagger报错Type javax.servlet.http.HttpServletRequest not present解决办法
- Springboot整合Swagger2和Swagger3全过程
- springboot整合swagger3报Unable to infer base url错误问题
- SpringBoot整合Swagger3生成接口文档的示例代码
- Springboot整合Swagger2后访问swagger-ui.html 404报错问题解决方案
- springboot整合swagger3和knife4j的详细过程
- Springboot整合Swagger3全注解配置(springdoc-openapi-ui)
- SpringBoot整合Swagger3生成接口文档过程解析
相关文章
Spring ApplicationListener源码解析
这篇文章主要为大家介绍了Spring ApplicationListener源码解析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2023-01-01
Java中比较器Comparator和Comparable的区别
这篇文章主要介绍了Java中比较器Comparator和Comparable的区别,我们在使用 Collections.sort()对链表进行排序时,常常需要根据不同情况自定义排序规则,今天我们来看看比较器之间的区别,需要的朋友可以参考下2023-08-08


最新评论