问题:
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();
}