Swagger2匹配多个controller代码实例
作者:贾树丙 时间:2022-07-31 03:42:24
方法一:使用多个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();
}
来源:https://www.cnblogs.com/acm-bingzi/p/swagger2-controller.html
标签:swagger,匹配,controller
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
基于Java的guava开源库工具类
2022-04-07 05:37:53
永久解决idea git log乱码的问题
2022-01-10 06:13:13
![](https://img.aspxhome.com/file/2023/4/63434_0s.jpg)
如何关闭 IDEA 自动更新
2021-11-04 17:17:30
![](https://img.aspxhome.com/file/2023/7/62107_0s.png)
Java并发编程之线程创建介绍
2021-11-14 13:55:40
spring boot项目没有mainClass如何实现打包运行
2021-10-24 11:29:20
Java基于享元模式实现五子棋游戏功能实例详解
2023-07-23 16:20:18
![](https://img.aspxhome.com/file/2023/4/57714_0s.png)
SpringBoot动态修改日志级别的操作
2022-10-31 05:00:30
![](https://img.aspxhome.com/file/2023/6/67116_0s.png)
java中String的一些方法深入解析
2023-11-25 21:48:56
![](https://img.aspxhome.com/file/2023/2/60332_0s.png)
springboot读取配置文件中的参数具体步骤
2023-11-29 05:46:14
![](https://img.aspxhome.com/file/2023/2/59582_0s.png)
java并发高的情况下用ThreadLocalRandom来生成随机数
2022-10-30 12:42:03
![](https://img.aspxhome.com/file/2023/6/69076_0s.jpg)
redis redisson 集合的使用案例(RList、Rset、RMap)
2023-11-13 13:50:21
Flutter之Timer实现短信验证码获取60s倒计时功能的代码
2023-07-20 20:00:30
![](https://img.aspxhome.com/file/2023/8/89528_0s.gif)
Java计算两个程序运行时间的实例
2022-01-30 14:49:06
SpringBoot实现动态多线程并发定时任务
2023-12-12 01:58:26
![](https://img.aspxhome.com/file/2023/9/71689_0s.jpg)
Mapper批量插入Oracle数据@InsertProvider注解
2023-02-11 15:13:40
Spring Security 中如何让上级拥有下级的所有权限(案例分析)
2022-01-28 16:55:26
![](https://img.aspxhome.com/file/2023/9/68019_0s.jpg)
关于JWT之token令牌认证登录
2022-03-16 07:32:58
![](https://img.aspxhome.com/file/2023/8/69918_0s.png)
Spring Boot启动过程(四)之Spring Boot内嵌Tomcat启动
2023-09-21 00:16:18
![](https://img.aspxhome.com/file/2023/7/58577_0s.png)
mybatis中的if test判断入参的值问题
2023-11-16 08:13:44
![](https://img.aspxhome.com/file/2023/9/59579_0s.png)
Java try catch finally异常处理组合详解
2021-07-04 18:19:51