knife4j 的使用配置
关键词:swagger、springfox、swagger-bootstrap-ui
说明:一款更加美化,实用、方便生成漂亮离线文档的接口文档工具
- 第一步:引入依赖
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.8</version>
<type>pom</type>
</dependency>
- 第二步:配置swagger
@EnableSwagger2
@Component
public class Swagger2 {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("default")
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("xxx.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("xxx接口说明")
.description("OpenAPI规范接口描述")
.version("v1.0")
.contact(new Contact("xxx公司", "http://xxx.com/", "xxx@xxx.com"))
.license("License")
.licenseUrl("http://xxx.com/")
.build();
}
}
- 第三步:控制器加swagger-ui 注解(略)
- 第四步:启动访问
启动springboot 项目
访问:localhost:port/doc.html