Knife4j配置
一、导入依赖
<!-- https://mvnrepository.com/artifact/com.github.xiaoymin/knife4j-spring-boot-starter -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.8</version>
</dependency>
<!-- <!– 避免版本冲突 –>-->
<!-- <dependency>-->
<!-- <groupId>com.google.guava</groupId>-->
<!-- <artifactId>guava</artifactId>-->
<!-- <version>29.0-jre</version>-->
<!-- </dependency>-->
二、编写配置类
@Configuration
@EnableSwagger2WebMvc
//@EnableSwaggerBootstrapUI
@EnableKnife4j
public class Knife4jConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.email"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
Contact contact = new Contact("zhuyijun", "http://localhost:9029/doc.html", "zhuyijun@hatech.com.cn");
return new ApiInfoBuilder()
.title("SpringBoot项目 后台服务API接口文档")
.description("使用 knife4j 搭建的后台服务API接口文档")
.termsOfServiceUrl("http://localhost:9029/")
.contact(contact)
.version("1.0.0")
.build();
}
}
三、测试
访问http://localhost:9029/doc.html