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

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条)

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services