Spring Boot 3.x 整合Swagger的示例教程
作者: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生成接口文档过程解析