【原】Spring Boot 配置swagger2沒有文檔解決方案


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM