@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。