pom文件依赖
<properties>
<springfox-swagger2.version>2.9.2</springfox-swagger2.version>
<springfox-swagger-ui.version>2.9.2</springfox-swagger-ui.version>
<knife4j-spring-boot-starter.version>2.0.2</knife4j-spring-boot-starter.version>
<springfox-bean-validators.version>2.9.2</springfox-bean-validators.version>
<shiro-redis.version>3.2.3</shiro-redis.version>
<shiro-spring.version>1.4.1</shiro-spring.version>
</properties>
<dependencies>
<!--swagger2 依赖-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-swagger2.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-swagger-ui.version}</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j-spring-boot-starter.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>${springfox-bean-validators.version}</version>
</dependency>
</dependencies> <properties>
<springfox-swagger2.version>2.9.2</springfox-swagger2.version>
<springfox-swagger-ui.version>2.9.2</springfox-swagger-ui.version>
<knife4j-spring-boot-starter.version>2.0.2</knife4j-spring-boot-starter.version>
<springfox-bean-validators.version>2.9.2</springfox-bean-validators.version>
<shiro-redis.version>3.2.3</shiro-redis.version>
<shiro-spring.version>1.4.1</shiro-spring.version>
</properties>
<dependencies>
<!--swagger2 依赖-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-swagger2.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-swagger-ui.version}</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j-spring-boot-starter.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>${springfox-bean-validators.version}</version>
</dependency>
</dependencies>
配置文件 进行分组配置
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
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.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
@EnableKnife4j
public class SwaggerConfig {
/**
* 设置基础分组(包含所有注解标注过的接口)
* @return
*/
@Bean
public Docket docketBase_seller() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo_seller())
.select()
.apis(RequestHandlerSelectors.basePackage("com.xinfeng.controller.seller"))
.paths(PathSelectors.any()) //正则匹配请求路径,并分配至当前分组,当前所有接口
.build()
.groupName("卖家管理系统") //分组名称
.globalOperationParameters(null);
}
private ApiInfo apiInfo_seller() {
return new ApiInfoBuilder()
.title("新丰商城-卖家接口模块")
.description("新丰商城-193中级项目")
.termsOfServiceUrl("")
.version("1.0")
.build();
}
@Bean
public Docket docketBase_setting() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo_setting())
.select()
.apis(RequestHandlerSelectors.basePackage("com.xinfeng.controller.setting"))
.paths(PathSelectors.any()) //正则匹配请求路径,并分配至当前分组,当前所有接口
.build()
.groupName("商城管理系统") //分组名称
.globalOperationParameters(null);
}
private ApiInfo apiInfo_setting() {
return new ApiInfoBuilder()
.title("新丰商城-商城管理系统")
.description("新丰商城-193中级项目")
.termsOfServiceUrl("")
.version("1.0")
.build();
}
@Bean
public Docket docketBase_home() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo_home())
.select()
.apis(RequestHandlerSelectors.basePackage("com.xinfeng.controller.home"))
.paths(PathSelectors.any()) //正则匹配请求路径,并分配至当前分组,当前所有接口
.build()
.groupName("商城系统") //分组名称
.globalOperationParameters(null);
}
private ApiInfo apiInfo_home() {
return new ApiInfoBuilder()
.title("新丰商城-商城系统")
.description("新丰商城-193中级项目")
.termsOfServiceUrl("")
.version("1.0")
.build();
}
}
标签:Swagger,配置,version,分组,import,springfox,apiInfo,商城 From: https://blog.51cto.com/u_14671216/6397692