swaggerUI 配置扫描多个包路径
package com.tyzn; import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.base.Predicate; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.RequestHandler; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; /** * @author jock * @Title: Swagger2 * @ProjectName imooc-videos-dev * @Description: TODO */ @SuppressWarnings("all") @Configuration @EnableSwagger2//开启 public class Swagger2 { // 定义分隔符 private static final String splitor = ";"; @Bean public Docket createRestApi(){ return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() //API标签所在位置 .apis(basePackage("com.tyzn.controller.api" + splitor + "com.tyzn.controller.backApi")) //.apis(RequestHandlerSelectors.basePackage("com.tyzn.controller.backApi")) .paths(PathSelectors.any()) .build(); } //标题设置 private ApiInfo apiInfo(){ return new ApiInfoBuilder() //题目 .title("**********api接口") //设置联系人 .contact(new Contact("**********","http://www.xxx.com","xxxxxx@qq.com")) //文档描述 .description("描述信息") //版本号 .version("1.0").build(); } public static Predicate<RequestHandler> basePackage(final String basePackage) { return input -> declaringClass(input).transform(handlerPackage(basePackage)).or(true); } private static Function<Class<?>, Boolean> handlerPackage(final String basePackage) { return input -> { // 循环判断匹配 for (String strPackage : basePackage.split(splitor)) { boolean isMatch = input.getPackage().getName().startsWith(strPackage); if (isMatch) { return true; } } return false; }; } private static Optional<? extends Class<?>> declaringClass(RequestHandler input) { return Optional.fromNullable(input.declaringClass()); } }