一、引入依赖
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>3.0.2</version>
</dependency>
二、配置
package com.sofia.sofro.config;
import lombok.extern.slf4j.Slf4j;
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.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
@Slf4j
@Configuration
public class Swagger2Config{
@Bean
public Docket defaultApi2() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.title("Sofro后台服务API接口文档")
.version("1.0")
.description("后台API接口")
.contact(new Contact("Sofia", "", ""))
.build())
.pathMapping("/")
.select()
.apis(RequestHandlerSelectors.basePackage("com.sofia.sofro.modules"))
.paths(PathSelectors.any())
.build();
}
}
knife4j:
enable: true
production: false
basic:
enable: true
username: admin
password: 123456