java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > Spring Boot 3.x 整合Swagger

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,因为:

第一步:添加依赖:

<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内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文