SpringBoot2.7.5集成SpringDoc

文章目录

  • SpringBoot2.7.5集成SpringDoc
    • 引入依赖
    • 配置SpringDoc
    • 启动服务

SpringBoot2.7.5集成SpringDoc

引入依赖

修改pom.xml


<dependency>
    <groupId>org.springdocgroupId>
    <artifactId>springdoc-openapi-uiartifactId>
    <version>${springdoc.version}version>
dependency>

配置SpringDoc

修改application.yaml

springdoc:
  swagger-ui:
    path: api-doc                     #自定义文档访问的地址
  packages-to-scan: com.graduation    #需要扫描的包路径
  paths-to-match: /*                  #匹配的url路径

增加配置类SwaggerConfig.class

import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

    @Bean
    public OpenAPI springShopOpenAPI() {
        return new OpenAPI()
                .info(new Info().title("SpringShop API")
                        .description("Spring shop sample application")
                        .version("v0.0.1")
                        .license(new License().name("Apache 2.0").url("http://springdoc.org")))
                .externalDocs(new ExternalDocumentation()
                        .description("SpringShop Wiki Documentation")
                        .url("https://springshop.wiki.github.org/docs"));
    }
}

启动服务

打开http://localhost:8080/api-doc
SpringBoot2.7.5集成SpringDoc_第1张图片

你可能感兴趣的:(SpringBoot,java,spring,开发语言,springboot)