zfs-swagger-ui 独立的测试系统

这个就不需要你引入我的jar包了.是不是放心很多了!!!

效果图

zfs-swagger-ui 独立的测试系统
zfs-swagger-ui 独立的测试系统
zfs-swagger-ui 独立的测试系统
zfs-swagger-ui 独立的测试系统

如何使用??

首先,你的项目中需要引入swagger2的相关配置,如下

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

. 配置类内容如下 (将扫描的包路径进行修改就ok了)

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.SecurityScheme;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@EnableSwagger2
@Configuration
@ComponentScan("cn.zfs")
public class SwaggerConfig extends WebMvcConfigurerAdapter {

    /**
     * 如果你在配置文件中配置了页面访问的相关信息,就需要有该方法,否则无法访问swagger-ui.html
     *
     * @param registry --
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

    @Bean
    public Docket createRestApi() {
        ArrayList<SecurityScheme> securitySchemes = new ArrayList<>();
        securitySchemes.add(new ApiKey("Set-Cookie", "Cookie", "header"));
        securitySchemes.add(new ApiKey("Authorization", "Authorization", "header"));
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo()).groupName("1")
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.zfs.swagger.ui.one.controller"))
                .paths(PathSelectors.any())
                .build().securitySchemes(securitySchemes);
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Spring Boot中使用Swagger2构建Restful Api") //设置文档的标题
                .description("Spring boot Swagger2 study:Spring boot Swagger2 study") //设置文档的描述->1.Overview
                .termsOfServiceUrl("Spring boot Swagger2 study") //设置文档的License信息->1.3 License information
                .contact("qhong")//设置文档的联系方式->1.2 Contact information
                .version("1.0")
                .build();
    }

    @Bean
    public Docket createRestApi2() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo2()).groupName("2")
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.zfs.swagger.ui.two.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo2() {
        return new ApiInfoBuilder()
                .title("Spring Boot中使用Swagger2构建Restful Api") //设置文档的标题
                .description("Spring boot Swagger2 study:Spring boot Swagger2 study") //设置文档的描述->1.Overview
                .termsOfServiceUrl("Spring boot Swagger2 study") //设置文档的License信息->1.3 License information
                .contact("qhong")//设置文档的联系方式->1.2 Contact information
                .version("1.0")
                .build();
    }

}

然后下载jar包

http://central.maven.org/maven2/cn/zhangfusheng/zfs-swagger-ui/1.0.1.web/zfs-swagger-ui-1.0.1.web.jar
使用启动命令,启动

java -jar zfs-swagger-ui-1.0.1.web.jar --server.port=9090

访问:
localhost:9090/swagger-zfs-ui.html
点击init按钮,进行初始化