swagger2 如何匹配多个controller

Posted 阿丙的博客园

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swagger2 如何匹配多个controller相关的知识,希望对你有一定的参考价值。

使用多个controller的共同拥有的父类,即精确到两个controller的上一级

如下:

@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.shubing"))
            .paths(PathSelectors.any())
            .build();
}

 

使用以下两种,都是错误的

@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.shubing.*.controller"))
            .paths(PathSelectors.any())
            .build();
}
@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.shubing.course.controller"))
            .apis(RequestHandlerSelectors.basePackage("com.shubing.user.controller"))
            .paths(PathSelectors.any())
            .build();
}

 

 

以上是关于swagger2 如何匹配多个controller的主要内容,如果未能解决你的问题,请参考以下文章