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

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

时间:2018-01-10 11:39:59      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:handler   http   ack   log   dock   .class   pack   highlight   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,页面可以出来就是接口文档出不来。于是替换如下:

 @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没有文档解决方案

标签:handler   http   ack   log   dock   .class   pack   highlight   nbsp   

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

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