zoukankan      html  css  js  c++  java
  • 【原】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。

  • 相关阅读:
    vue中 根据音频 获取音频的时长
    获取dom位置信息
    react笔记
    Git 基础命令
    vue 笔记
    倒计时
    删留言
    python 类之类变量与实例变量
    python 类的定义
    python 列表推导式
  • 原文地址:https://www.cnblogs.com/zdd-java/p/8256961.html
Copyright © 2011-2022 走看看