jeecg-boot怎么配置swagger扫描多个包?

1:重写basePackage方法

// 定义分隔符
    private static final String splitor = ";";
	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(apiInfo())
				.select()
				//此包路径下的类,才生成接口文档
//				.apis(RequestHandlerSelectors.basePackage("org.jeecg.modules"))
				.apis(basePackage("com.csp"+splitor+"org.jeecg.modules"))//重点,这里RequestHandlerSelectors去掉了。
				//加了ApiOperation注解的类,才生成接口文档
	            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
				.paths(PathSelectors.any())
				.build()
				.securitySchemes(Collections.singletonList(securityScheme()));
				//.globalOperationParameters(setHeaderToken());
	}
    public static Predicate basePackage(final String basePackage) {
        return input -> declaringClass(input).transform(handlerPackage(basePackage)).or(true);
    }
    private static Function, 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> declaringClass(RequestHandler input) {
        return Optional.fromNullable(input.declaringClass());
    }

你可能感兴趣的:(jeecgboot,javaSE,Spring,Boot)