@Bean public Docket customImplementation(){ return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("com.xx.controller")) .build() .directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class) .directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class) .apiInfo(apiInfo()); }
如上图所示,使用basePackage扫描com.xx.controller,启动项目后访问http://127.0.0.1:8088/swagger-ui.html,页面可以出来就是接口文档出不来。于是替换如下:
@Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) .build(); }
将basePackage扫描的条件改为RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class),扫描ApiOperation注解修饰的Controller后重启项目,接口文档正常显示。
原文地址:https://www.cnblogs.com/zdd-java/p/8256961.html
时间: 2024-10-07 16:56:05