1、引入依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
2、Application同级下创建config包
@Configuration
@EnableSwagger2
@Profile({"default", "dev", "test"})
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2).pathMapping("/").select()
.apis(RequestHandlerSelectors.basePackage("com.huohuo.note"))
.paths(PathSelectors.any()).build().apiInfo(apiInfo("OTHER-API(其它)"));
}
private ApiInfo apiInfo(String desc) {
return new ApiInfoBuilder().license("").title("火火笔记").description(desc).version("1.0.0")
.build();
}
@Bean
public Docket adminApi() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
.paths(PathSelectors.ant("/admin/**")).build().groupName("admin").pathMapping("/")
.apiInfo(apiInfo("ADMIN-API(管理端)"));
}
@Bean
public Docket h5Api() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
.paths(PathSelectors.ant("/h5/**")).build().groupName("h5").pathMapping("/")
.apiInfo(apiInfo("H5-API(用户端)"));
}
}