swagger报错No operations defined in spec!解决
程序员文章站
2022-05-29 16:47:00
...
swagger报错No operations defined in spec! 一般有2个原因:
- basePackage错误;
- path错误;
其中第2个path错误,path要是全匹配url,url是完整的,包含方法的url,本人因为path只写controller上的url,没写方法上的url,找了1天也没找到原因,看之前项目才发现url不是完整的url;如果不是完整的url,正则是/path/rest/pic/.*, 正则是 .*;
第1个basePackage错误,主要是扫描的包内没有controller,或者controller类上没有@Controller注解。
完整可用的配置类如下:
@Configuration @EnableSwagger2 public class Swagger2Config { @Value("${swagger.enable}") boolean swagger2enable; @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .enable(swagger2enable) .select() .apis(RequestHandlerSelectors.basePackage("com.test.controller")) .paths(doFilteringRules()) .build(); } private Predicate<String> doFilteringRules() { // return PathSelectors.any(); // return PathSelectors.regex("/report/.*"); // return Predicates.not(PathSelectors.regex("/error.*")); // return or(regex("/hello.*"), regex("/rest/adxSspFinanceManagement.*"));//success return or(regex("/rest/pic/url/query"), //此处必须为完整的url,到方法级别 regex("/rest/text/url/query/.*") //部分url的正则是 .* // regex("/api/v1/pop/bms/audit/.*") ); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("Check APIs") .description(" 测试环境地址:http://10.179.88.216:8083") .termsOfServiceUrl("http://10.179.88.216:8083") .contact("开发团队") .version("1.0") .build(); } }
下一篇: 开始学习Vue.js
推荐阅读
-
解决vue项目报错webpackJsonp is not defined问题
-
解决vue项目报错webpackJsonp is not defined问题
-
Resource Path Location Type Target runtime Apache Tomcat v6.0 is not defined(项目报错)已解决
-
Tomcat ssl报错Connector attribute SSLCertificateFile must be defined when using SSL with APR解决方法
-
MySQL中Multiple primary key defined报错的解决办法
-
Tomcat报错:The valid characters are defined in RFC 7230。解决办法
-
swagger报错No operations defined in spec!解决
-
swagger报错No operations defined in spec!解决
-
Resource Path Location Type Target runtime Apache Tomcat v6.0 is not defined(项目报错)已解决
-
Error: "DEVELOPER_DIR" is not defined at ./symbolicatecrash line 69. 报错解决