SpringBoot整合Knief4j
本文SpringBoot版本为2.6,版本不同操作可能会有不同
1.引入依赖
<!--添加swagger的依赖-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>3.0.2</version>
</dependency>
2.Knief4j配置类
@Configuration
@EnableSwagger2WebMvc
@Profile({"dev", "test"})
public class SwaggerConfig {
@Bean(value = "defaultApi2")
public Docket defaultApi2() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
// 这里一定要标注你控制器的位置
.apis(RequestHandlerSelectors.basePackage("org.lostarknotespring.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("项目名称")
.description("项目名称接口文档")
.version("1.0")
.build();
}
}
3.配置文件
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
profiles:
active: dev
标签:Knief4j,SpringBoot,defaultApi2,spring,apiInfo,build,整合
From: https://www.cnblogs.com/cymxd/p/18416574