欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SpringBoot集成 Swagger

程序员文章站 2022-05-20 21:33:04
...
1. 新建项目

SpringBoot集成 SwaggerSpringBoot集成 Swagger
SpringBoot集成 Swagger
SpringBoot集成 Swagger

2. 导入相关依赖
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
</dependency>

SpringBoot集成 Swagger

3. 编写一个示例程序

SpringBoot集成 Swagger

4. 编写 Swagger配置

SpringBoot集成 Swagger

5. 测试运行

http://localhost:8080/swagger-ui.html#/

6. 配置 Swagger
@Configuration
@EnableSwagger2  // 开启 Swagger2
public class SwaggerConfig {

    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());
    }

    public ApiInfo apiInfo(){
        Contact contact = new Contact("cxx", "#", "aaa@qq.com");

        return new ApiInfo(
                "Swagger API 文档",
                "略",
                "1.0",
                "#",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList()
        );
    }
}

SpringBoot集成 Swagger

相关标签: