融资项目——swagger2的配置与使用

swagger2是一个可以基于我们编写的接口自动生成接口文档和测试用例的工具。

其配置方法如下:

  1. 首先在pom.xml文件中导入依赖:

         <dependency>
             <groupId>io.springfox</groupId>
             <artifactId>springfox-swagger2</artifactId>
         </dependency>
         <!--swagger ui-->
                 <dependency>
                     <groupId>io.springfox</groupId>
                     <artifactId>springfox-swagger-ui</artifactId>
                 </dependency>
         <dependency>
             <groupId>com.github.xiaoymin</groupId>
             <artifactId>swagger-bootstrap-ui</artifactId>
             <version>1.9.2</version>
         </dependency>
    
  2. 创建相关的配置类:

    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import springfox.documentation.spi.DocumentationType;
    import springfox.documentation.spring.web.plugins.Docket;
    import springfox.documentation.swagger2.annotations.EnableSwagger2;

    @Configuration
    @EnableSwagger2
    public class Swagger2Config {
    @Bean
    public Docket apiConfig(){
    return new Docket(DocumentationType.SWAGGER_2);
    }

    }

以上就是配置的步骤。

其次,如果我们想要使用Swagger2。可以在开启服务之后,键入"http://localhost:xxxx(端口号)/swagger-ui.html"即可进入。

相关推荐
飘零未归人6 个月前
pringboot2集成swagger2出现guava的FluentIterable方法不存在
swagger2
归去来 兮7 个月前
Swagger3 使用详解
swagger·接口文档·swagger2·swagger3
qq_450077949 个月前
融资项目——swagger2的注解
swagger2