注:该文档使用于SpringBoot 2.2.x — 2.5.x
引入依赖
1 2 3 4 5 6
   |  <dependency>     <groupId>com.github.xiaoymin</groupId>     <artifactId>knife4j-spring-boot-starter</artifactId>     <version>2.0.9</version> </dependency>
 
  | 
 
Knife4j配置类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
   | import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
 
 
 
 
 
 
 
 
  @Configuration @EnableSwagger2WebMvc public class Knife4jConfig {
      @Bean(value = "dockerBean")     public Docket dockerBean() {                  return new Docket(DocumentationType.SWAGGER_2)                          .apiInfo(new ApiInfoBuilder()                                            .title("xiaofei-utils 接口测试文档")                                            .description("xiaofei-utils 接口测试文档")                                            .termsOfServiceUrl("https://utils.naste.top:1024/")                                            .contact(new Contact("XiaoFei", "https://utils.naste.top:1024/", "1903078434@qq.com"))                                            .license("所有版权归XiaoFei所有")                                            .licenseUrl("https://utils.naste.top:1024/")                                            .version("1.0")                                            .build())                          .groupName("xiaofei-utils")             .select()                          .apis(RequestHandlerSelectors.basePackage("com.xiaofei.utils.controller"))             .paths(PathSelectors.any())             .build();     } }
 
   | 
 
Knife4j配置文件
部分配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14
   |  knife4j:      enable: true      basic:          enable: false          username: root          password: root      production: false
 
  | 
 
完整配置文件
参考文档:https://doc.xiaominfo.com/docs/features/enhance
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
   | knife4j:   enable: true   documents:     -       group: 2.X版本       name: 接口签名       locations: classpath:sign/*   setting:     language: zh-CN     enableSwaggerModels: true     enableDocumentManage: true     swaggerModelName: 实体类列表     enableVersion: false     enableReloadCacheParameter: false     enableAfterScript: true     enableFilterMultipartApiMethodType: POST     enableFilterMultipartApis: false     enableRequestCache: true     enableHost: false     enableHostText: 192.168.0.193:8000     enableHomeCustom: true     homeCustomLocation: classpath:markdown/home.md     enableSearch: false     enableFooter: false     enableFooterCustom: true     footerCustomContent: Apache License 2.0 | Copyright  2019-[小飞Knife4j接口文档](https://utils.naste.top/)     enableDynamicParameter: false     enableDebug: true     enableOpenApi: false     enableGroup: true   cors: false   production: false   basic:     enable: false     username: test     password: 12313
   |