Swagger文档-knife4j
1.依赖
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<!--在引用时请在maven中央仓库搜索3.X最新版本号-->
<version>3.0.3</version>
</dependency>
2.配置
package com.tf.commons;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.*;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* Swagger配置
*/
@Configuration
@EnableSwagger2
@Profile({"local", "dev", "test"})
public class SwaggerConfig {
@Bean(value = "knife4jDocket")
public Docket knife4jDocket() {
String groupName="one";
return new Docket(DocumentationType.OAS_30)
.apiInfo(new ApiInfoBuilder()
.title("knife4j API ")
.description("knife4j API 接口文档")
.termsOfServiceUrl("http://chenyaoyao.com")
.contact(new Contact("陈遥遥","http://127.0.0.1","741462428@qq.com"))
.version("v3.0.3")
.build())
//分组名称
.groupName(groupName)
.select()
//这里指定Controller扫描包路径
.apis(RequestHandlerSelectors.basePackage("com.tf.controller"))
.paths(PathSelectors.any())
.build();
}
}
3.注意点
如果配置了拦截器或者过滤器,需要放行 /v3/* , /doc.html , 等地址,
具体放行地址可以访问 http://localhost:8080/doc.html 时,打开F12,查看被拦截的接口地址。