springBoot 配置SwaggerUi接口测试

1. 通过maven导入jar包

<!-- 引入swagger相关的jar -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>

2. 编写SwaggerConfig配置文件

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .pathMapping("/")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.tw.skynet.controller"))   //项目接口类路径
                .paths(PathSelectors.any())
                .build().apiInfo(new ApiInfoBuilder()
                        .title("API接口调试")
                        .description("详细信息")
                        .version("1.0")
                        .contact(new Contact(
                                "drgs",  //项目名称
                                "https://www.00.cn",  //备注网址
                                "11111111111@163.com"))  //备注邮箱地址
                        .license("The Apache License")
                        .licenseUrl("https://www.00.cn")
                        .build()
                );
    }
}

 

posted @ 2022-04-14 14:09  _情书  阅读(137)  评论(0编辑  收藏  举报