pom.xml 配置
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.7</version>
</dependency>
config 配置
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.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
/**
* Knife4j配置文件
*
* @author
*/
@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfiguration {
@Bean(value = "knife4jApi2")
public Docket defaultApi2() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.title("项目-API")
.description("项目-SwaggerAPI管理")
.termsOfServiceUrl("http://localhost:9110/v2/api-docs?group=1.0")
.version("1.0")
.build())
.groupName("1.0")
.select()
.apis(RequestHandlerSelectors.basePackage("com.XXX.controller"))
.paths(PathSelectors.any())
.build();
}
}