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

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

方法二:指定所有controller的都实现的一个接口,比如@RestController

@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.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的更多相关文章

  1. Swagger如何匹配多个Controller类或者目录

    方法一(最普通的方式):匹配一个controller目录下的所有controller类. 1 @Bean 2 public Docket creatRestApi(){ 3 return new Do ...

  2. EF语句拦截器-匹配当前的Controller,Action,User

    示例代码,ps:一切都能实现,关键是你尝试的方向,别把简单问题复杂化导致进入死胡同出不来. using Mobile360.Core.Interfaces; using Mobile360.Core. ...

  3. 在ASP.NET非MVC环境中(WebForm中)构造MVC的URL参数,以及如何根据URL解析出匹配到MVC路由的Controller和Action

    目前项目中有个需求,需要在WebForm中去构造MVC的URL信息,这里写了一个帮助类可以在ASP.NET非MVC环境中(WebForm中)构造MVC的URL信息,主要就是借助当前Http上下文去构造 ...

  4. [ASP.NET MVC 小牛之路]10 - Controller 和 Action (2)

    继上一篇文章之后,本文将介绍 Controller 和 Action 的一些较高级特性,包括 Controller Factory.Action Invoker 和异步 Controller 等内容. ...

  5. SpringMVC从Controller跳转到另一个Controller(转)

    http://blog.csdn.net/jackpk/article/details/44117603 [PK亲测] 能正常跳转的写法如下: return "forward:aaaa/bb ...

  6. Controller 和 Action (2)

    Controller 和 Action (2) 继上一篇文章之后,本文将介绍 Controller 和 Action 的一些较高级特性,包括 Controller Factory.Action Inv ...

  7. 【ASP.NET MVC 学习笔记】- 11 Controller和Action(2)

    本文参考:http://www.cnblogs.com/willick/p/3331513.html 1.MVC一个请求的发出至action返回结果的流程图如下: 重点是Controller Fact ...

  8. Swagger2

    参考文档:https://www.jianshu.com/p/5ae7267385b9 官网:https://swagger.io/ 注解参考:https://blog.csdn.net/weixin ...

  9. ASP.NET Core MVC的路由参数中:exists后缀有什么作用,顺便谈谈路由匹配机制

    我们在ASP.NET Core MVC中如果要启用Area功能,那么会看到在Startup类的Configure方法中是这么定义Area的路由的: app.UseMvc(routes => { ...

随机推荐

  1. python二:数据类型举例练习--小白博客

    一.#字符串 res = 'hello,world' 1.#字符串切片取值:******* print(res[0:5]) 顾头不顾尾,取下标0-4的字符 print(res[0:-1:2]) 步长为 ...

  2. 剑指Offer-- 翻转链表 (python版)

    输入一个链表,反转链表后,输出链表的所有元素. # -*- coding:utf-8 -*- # class ListNode: # def __init__(self, x): # self.val ...

  3. Paypal2017实习生-软件开发-B卷

    1. [编程|15分] Calculate survival fishes时间限制:1秒空间限制:32768K题目描述Given two zero-indexed arrays A and B con ...

  4. Codeblocks 遇到的问题 Cannot open output file, permission denied

    Codeblocks下运行C++的程序时,偶尔会出现  Cannot open output file, permission denied 的问题,导致不能够编译. 在 Stack Overflow ...

  5. Python_每日习题_0005_三数排序

    # 题目: # 输入三个整数x,y,z,请把这三个数由大到小输出. # 程序分析: 练练手就随便找个排序算法实现一下,偷懒就直接调用函数. #方法一:排序 raw = [] for i in rang ...

  6. hdu 5584 LCM Walk

    没用运用好式子...想想其实很简单,首先应该分析,由于每次加一个LCM是大于等于其中任何一个数的,那么我LCM加在哪个数上面,那个数就是会变成大的,这样想,我们就知道,每个(x,y)对应就一种情况. ...

  7. Divisors of Two Integers CodeForces - 1108B (数学+思维)

    Recently you have received two positive integer numbers xx and yy. You forgot them, but you remember ...

  8. 《梦断代码》Scott Rosenberg著(二)

    书中有一段说的是一个闪烁缺陷——在改变某软件中某个窗体的尺寸时,屏幕会闪烁一秒钟左右.虽然该缺陷不会影响程序运行,但它不符合作者的审美观,历时六个多月仍然没能修正.其实在日常的编程中也有许多小bug的 ...

  9. Telnet服务器和客户端请求处理

    Telnet服务器和客户端请求处理 本文的控制台项目是根据SuperSocket官方Telnet示例代码进行调试的,官方示例代码:Telnet示例. 开始我的第一个Telnet控制台项目之旅: 创建控 ...

  10. MySQL数据库导入错误:ERROR 1064 (42000) 和 ERROR at line xx:

    https://www.cnblogs.com/yeahgis/p/4358973.html mysql -hlocalhost -uroot -proot --default-character-s ...