zoukankan      html  css  js  c++  java
  • javaweb集成swagger

    一、添加依赖 

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

    二、添加类

      

    @EnableWebMvc
    @EnableSwagger2
    @Configuration
    public class SwaggerConfig {
     
      @Bean
      public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.z*.b*.c*.controller")) 
            // 注意修改此处的包名
            .paths(PathSelectors.any())
            .build();
      }
     
      private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
            .title("接口列表 v1.1.0") // 任意,请稍微规范点
            .description("接口测试") // 任意,请稍微规范点
            .termsOfServiceUrl("http://url/swagger-ui.html") 
            // 将“url”换成自己的ip:port
           .contact("laowu") // 无所谓(这里是作者的别称)
            .version("1.1.0")
            .build();
      }
    }

    三、在spring-mvc.xml中添加

    <mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
    <mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
     

    四、类、方法上添加注解

    @ApiOperation(value = "名称", httpMethod = "POST")
    @ApiParam(required = true, name = "test", value = "参数") 

    五、访问  localhost:8080/项目名/swagger-ui.html

    六、添加拦截过滤

    <mvc:exclude-mapping path="/swagger*/**"></mvc:exclude-mapping>
    <mvc:exclude-mapping path="/v2/**"></mvc:exclude-mapping>
    <mvc:exclude-mapping path="/webjars/**"></mvc:exclude-mapping>

     转自:http://www.jb51.net/article/130208.htm

      

  • 相关阅读:
    集成学习值Adaboost算法原理和代码小结(转载)
    集成学习原理小结(转载)
    2019阿里校招测评题,光明小学完全图最短路径问题(python实现)
    第八节、图片分割之GrabCut算法、分水岭算法
    Scala2.11.8 spark2.3.1 mongodb connector 2.3.0
    spark 实现动态日期读取
    Idea 201601注册码
    linux下的crontab服务
    spark MySQL jar 包
    scala 日期格式转换
  • 原文地址:https://www.cnblogs.com/xdcr/p/8891911.html
Copyright © 2011-2022 走看看