在最近的新项目开发中,深感编写接口文档的低效,维护困难。文档需要更新的时候,需要再次发送一份给前端和别的服务调用方,经常出现文档更新交流不及时的情况,最后果断放弃文档编写,使用招摇,实时生成在线文档,这里集成的是swagger2
我们项目采用的是springboot,所以本文介绍的是在springboot中集成swagger2
- pom.xml中引入的jar包支持,阿里巴巴私服有该JAR包
<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>
2,新建swggerconfig类,直接建在springboot项目中
package com.crb.init;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.d