swagger2无法扫描到其他工程的controller API

问题:

swagger无法扫描到自定义工程的controller
在这里插入图片描述
思考:

1、可能是当前工程没有把工具类导入进来

2、swagger配置有问题

经maven命令maven idea:idea检查,该命令可以检查依赖是否完成导入,控制台报错common工程下的两个子工程common-utils和service-base could not found

我将根工程clean、install,后台报错

Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.2.1.RELEASE:repackage (repackage) on project common-utils: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.2.1.RELEASE:repackage failed: Unable to find main class

原因很明显,无法找到common-utils的main类,尝试更改过maven的插件,但都没有起作用,因此从报错信息入手,给common-utils、service-base创建两个启动类,重新执行maven idea:idea不会报错,问题解决

但前台swagger依然扫描不到对应的api

swagger config问题代码

    @Bean
    public Docket webApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("webApi")
                .apiInfo(webApiInfo())
                .select()
                .paths(Predicates.not(PathSelectors.regex("/admin/.*")))
                .paths(Predicates.not(PathSelectors.regex("/error.*")))
                .build();

    }

问题在于

.paths(Predicates.not(PathSelectors.regex("/admin/.*")))

该配置会不监控admin路径,因此把它去掉就可以

更改后代码:

    @Bean
    public Docket webApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("webApi")
                .apiInfo(webApiInfo())
                .select()
                //这一句可加可不加,该配置可以扫描所有有ApiOperation注解的api,用这种方式更灵活
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(Predicates.not(PathSelectors.regex("/error.*")))
                .build();
    }
  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值