月明星稀灬 2018-08-06 02:20 采纳率: 100%
浏览 1966
已采纳

swgger2配置了之后无法访问接口主页

swgger2配置了之后无法访问接口主页。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

  • 写回答

4条回答 默认 最新

  • 玄尺 2018-08-06 02:24
    关注

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    swagger配置
    1、pom依赖

    <dependency>
         <groupId>io.springfox</groupId>
         <artifactId>springfox-swagger-ui</artifactId>
         <version>2.6.1</version>
    </dependency>
    <dependency>
         <groupId>io.springfox</groupId>
         <artifactId>springfox-swagger2</artifactId>
         <version>2.6.1</version>
    </dependency>

    @EnableSwagger2
    @Configuration
    public  class  SwaggerConfig  extends  WebMvcConfigurationSupport  {

         @Bean
         public  Docket  createRestApi(PropertiesConfig  propertiesConfig)  {
             return  new  Docket(DocumentationType.SWAGGER_2)
                     .apiInfo(apiInfo(propertiesConfig))
                     .select()
                     .apis(RequestHandlerSelectors. basePackage("com.phicomm.mobile.hermes.hamal.controller"))
                     .paths(propertiesConfig.isSwaggerEnabled()  ?  PathSelectors. any()  :  PathSelectors.none())
                     .build();
         }

         private  ApiInfo  apiInfo(PropertiesConfig  propertiesConfig)  {
             return  new  ApiInfoBuilder()
                     .title(propertiesConfig.getSwaggerTitle())
                     .termsOfServiceUrl(propertiesConfig.getSwaggerServiceUrl())
                     .contact( new  Contact(propertiesConfig.getSwaggerContactName(),
                             propertiesConfig.getSwaggerContactUrl(),
                             propertiesConfig.getSwaggerContactEmail()))
                     .version(propertiesConfig.getSwaggerVersion())
                     .build();
         }

    }

    2、controller上的注解

    @Api(value  =  "TestController",  description  =  "test  the  swagger  API  TestController")

    3、具体的接口的注解

    @ApiOperation(value  =  "test  echo",  notes  =  "直接返回输入参数",  response  =  CommonResponse.class)

    4、参数的注解

    @ApiParam(value  =  "什么参数都可以"  ,required=true)

    5、响应状态码

    @ApiResponses(value  =  {@ApiResponse(code  =  405,  message  =  "Invalid  input",  response  =  PlanSyncBean.class)  })



    结果:

    http://localhost:8080/swagger-ui.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改