码迷,mamicode.com
首页 > 编程语言 > 详细

【原】Spring Boot 配置swagger2没有文档解决方案

时间:2018-01-10 11:28:38      阅读:671      评论:0      收藏:0      [点我收藏+]

标签:post   浏览器   解决   没有   and   mod   info   base   nbsp   

@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, Swagger UI 能正常加载到浏览器, 问题是只有标题抬头,没有接口文档。

   于是替换如下:

 @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后重启项目,接口文档正常显示。

【原】Spring Boot 配置swagger2没有文档解决方案

标签:post   浏览器   解决   没有   and   mod   info   base   nbsp   

原文地址:https://www.cnblogs.com/zdd-java/p/8256965.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!