swagger-bootstrap-ui https://doc.xiaominfo.com/guide/
一、引入swagger
二、引入swagger-bootstrap-ui 包
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.6</version>
</dependency>
三、启用
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class Swagger2Config {
@Bean
public Docket createRestApi() {
Docket docket = new Docket(DocumentationType.SWAGGER_2)
// .enable(false) // 是否启用swagger
.apiInfo(apiInfo())
.securitySchemes(createSecuritySchemeList())
// .pathMapping("/")
.select()
// 指定当前包路径,这里就添加了两个包,注意方法变成了basePackage,中间加上成员变量splitor
// .apis(basePackage("com.XX.api.controller.broad;com.XX.api.controller.village"))
.apis(RequestHandlerSelectors.basePackage("com.example.lwp.validatordemo.controller"))
.paths(PathSelectors.any())
.build();
return docket;
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("SpringBoot整合Swagger")
.description("SpringBoot整合Swagger,详细信息......")
.version("9.0")
.contact(new Contact("张三", "blog.csdn.net", "zhangsan@gmail.com"))
.contact(new Contact("李四", "blog.csdn.net", "zhangsan@gmail.com"))
.termsOfServiceUrl("http://localhost111:8080/")
// .license("The Apache License")
// .licenseUrl("http://www.baidu.com")
.build();
}
private List<SecurityScheme> createSecuritySchemeList(){
List<SecurityScheme> list = new ArrayList<>();
list.add(new ApiKey("access_token", "access_token鉴权值", "header"));
// list.add(new ApiKey("access_token1", "access_token1鉴权值", "query"));
return list;
}
}