Spring Boot中級篇-整合Swagger2分組文件
阿新 • • 發佈:2018-11-13
Swagger配置檔案
這裡配置兩個分組admin【後臺管理介面】、wechat【微信管理介面】
@Configuration @EnableSwagger2 public class Swagger2 { public static final String SWAGGER_SCAN_ADMIN_PACKAGE = "com.jacksony.module.admin.controller"; public static final String ADMIN_VERSION = "1.0.0"; public static final String SWAGGER_SCAN_WX_PACKAGE = "com.jacksony.module.wechat.controller"; public static final String WX_VERSION = "1.0.0"; @Bean public Docket createAdminRestApi() { return new Docket(DocumentationType.SWAGGER_2) .groupName("後臺管理介面") .apiInfo(apiAdminInfo()) .select() .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_ADMIN_PACKAGE))//api介面包掃描路徑 .paths(PathSelectors.regex(".*/admin/.*"))//可以根據url路徑設定哪些請求加入文件,忽略哪些請求 .build(); } private ApiInfo apiAdminInfo() { return new ApiInfoBuilder() .title("後臺管理介面")//設定文件的標題 .description("後臺資料管理")//設定文件的描述->1.Overview .version(ADMIN_VERSION)//設定文件的版本資訊-> 1.1 Version information .build(); } @Bean public Docket createWxRestApi() { return new Docket(DocumentationType.SWAGGER_2) .groupName("微信管理介面") .apiInfo(apiWxInfo()) .select() .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_WX_PACKAGE))//api介面包掃描路徑 .paths(PathSelectors.regex(".*/weixin/.*"))//可以根據url路徑設定哪些請求加入文件,忽略哪些請求 .build(); } private ApiInfo apiWxInfo() { return new ApiInfoBuilder() .title("微信管理介面")//設定文件的標題 .description("微信開發介面實現的文件")//設定文件的描述->1.Overview .version(WX_VERSION)//設定文件的版本資訊-> 1.1 Version information .build(); } }