Swagger配置使用

坚强是说给别人听的谎言 提交于 2019-12-27 09:36:04

依赖:

        <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>

        <!-- 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>

配置:

@EnableSwagger2
@Configuration
public class MySwaggerConfiguration {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //标题
                .title("Spring Boot 中使用 Swagger2 构建 RESTful APIs")
                //简介
                .description("hello swagger")
                //服务条款
                .termsOfServiceUrl("1. xxx\n2. xxx\n3. xxx")
                //作者个人信息
                .contact(new Contact("admin", "https://blog.csdn.net/A2735856944", "2735856944@qq.com"))
                //版本
                .version("1.0")
                .build();
    }
}

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!