关于api接口文档RAP和swagger
前言:
在之前的项目中用了将近一年的RAP,RAP是由阿里开源出来的,非常好用。github地址:https://github.com/thx/RAP。
当初在用此工具时,项目成员需要在接口文档在所改动后,发邮件到项目组成员,由于rap当时没有此功能,所以还下载源码,增加了发邮件功能。
将此功能代码commit到了社区,好像社区没有接纳合入。
后来使用了一年后,发现了swagger似乎使用很方便,直接跟代码进行结合,需要重新使用其他工具进行配合了。
所以以下时对swagger的spring集成说明。
swagger集成spring说明:
如果是在springboot集成swagger是非常方便和简单的,在网上一搜,或者到官网一看就明白了,这里不在赘述。
以下主要是自己集成到springmvc的改造点:
1、pom.xm文件,需要增加以下的依赖:
版本为:
<jackson-version>2.5.0</jackson-version>
<swagger-springmvc-version>1.0.2</swagger-springmvc-version>
增加的依赖为,:
<!-- 自动生成接口文档工具 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger-version}</version>
</dependency>
<!-- 自动生成接口文档工具 -->
<!-- 集成swagger2需要用到 一般都用fastJson,但是swagger是用到jackson的-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson-version}</version>
</dependency>
<!-- 集成swagger2需要用到 -->
2.增加一个swagger的配置文件:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* Swagger接口自动生成工具的配置
*
* @author liuhangjun
* @date 2017-01-22
*/
@Configuration
@EnableWebMvc
@EnableSwagger2
@ComponentScan("com.gradven.portalapi.controller")
public class SwaggerConfig extends WebMvcConfigurerAdapter {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.gradven.portalapi.controller")).build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
// 页面标题
.title("api门户 使用 Swagger2 构建RESTful API")
// 创建人
.contact(new Contact("gradven", null, "xxxxxxx@126.com"))
// 版本号
.version("1.0")
// 描述
.description("门户接口").build();
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
3.在spring的配置文件中将以上这个类进行注入:
<!-- swagger 配置 -->
<bean class="com.gradven.portalapi.commons.config.SwaggerConfig"/>
4.编写controller,访问swagger:
只要在com.gradven.portalapi.controller这个包下,编写controller,那么再访问http://localhost:port/swagger-ui.htm就可以看到接口了。
关于api接口文档RAP和swagger的更多相关文章
- Swagger 生成 PHP API 接口文档
Swagger 生成 PHP API 接口文档 Lumen微服务生成Swagger文档 1.概况 有同学反馈写几十个接口文档需要两天的工作量, 随着多部门之间的协作越来越频繁, 维护成本越来越高, 文 ...
- Swagger解决你手写API接口文档的痛
首先,老规矩,我们在接触新事物的时候, 要对之前学习和了解过的东西做一个总结. 01 痛 苦 不做.不行 之前,前后端分离的系统由前端和后端不同的编写,我们苦逼的后端工程师会把自己已经写完的A ...
- spring boot使用swagger生成api接口文档
前言 在之前的文章中,使用mybatis-plus生成了对应的包,在此基础上,我们针对项目的api接口,添加swagger配置和注解,生成swagger接口文档 具体可以查看本站spring boot ...
- 构建标准OpenStack API接口文档
1.构建API接口文档标准参考: http://docs.openstack.org/contributor-guide/api-guides.html 2.构建API接口文档步骤参考下面的Patch ...
- 整合swagger2生成Restful Api接口文档
整合swagger2生成Restful Api接口文档 swagger Restful文档生成工具 2017-9-30 官方地址:https://swagger.io/docs/specificati ...
- Api接口文档管理工具,你知道哪些呢?
上周看到有人在我的Github开源项目中提了个issue,说是否考虑接入swagger.那今天我就用swagger与其他接口文档工具做对比,同时说说Api接口文档工具的那点事.如今,在前后端分离开发的 ...
- SpringBoot + Swagger2 自动生成API接口文档
spring-boot作为当前最为流行的Java web开发脚手架,相信越来越多的开发者会使用其来构建企业级的RESTFul API接口.这些接口不但会服务于传统的web端(b/s),也会服务于移动端 ...
- api(接口)文档管理工具
api(接口)文档管理工具 欢迎光临:博之阅API管理平台 ,做为一个app开发者,还没有用到api管理工具,你就OUT了 点击进入:程序员精华博客大全
- 智表ZCELL产品V1.4.0开发API接口文档 与 产品功能清单
为了方便大家使用ZCELL,应网友要求,整理编写了相关文档,现与产品一起同步发布,供大家下载使用,使用过程中如有疑问,请与我QQ联系. 智表(ZCELL)V1.4.0版本 功能清单文档下载地址: 功 ...
随机推荐
- java的优先队列注意事项
在C++语言中,使用优先队列,直接构建一个lambda表达式,使用一个匿名函数指针.java比较函数的返回值不是bool型,只能是整型. 内部对应的C++匿名函数: // 匿名Comparator实现 ...
- Matlab移植到Eigen用到的词条
同型矩阵运算满足加法交换律.结合律:并存在单位元.逆元.和0元,为同型矩阵对加法的交换环. Eigen的简单运算参考:http://blog.163.com/jiaqiang_wang/blog/st ...
- coredata示意图
NSPersistentStoreCoordinator(Persistent Store Coordinator),缩写为PSC:存储信息+结构信息(MOM) NSManagedObjectMode ...
- jq 禁用复选框 和输入框
$('input').attr("readonly", ""); $('input').attr("disabled", "fal ...
- Java 8 函数接口详细教程
ay = new byte[array.length]; for (int i = 0; i < array.length; i++) { transformedArray[i] = funct ...
- LINUX - getopts
getopts optionString opt; optionString :所有参数组成的-参数串: opt:从optionString 每次取的参数值: 当optionString用[:]开头, ...
- phpstrom 汉化
-- ---------- _--------------------------------------------------- ------------------- ----- ------- ...
- dubbo-helloword(二)
项目框架搭建 工程目录创建 entity存放业务实体类 interface存放server接口 concumer是服务消费者(依赖interface和entity) provider是服务提供者(依赖 ...
- POJ 1379
模拟退火算法. 随机MAX个点,然后,退火移动,选取距离所有点中最短中最长者即可.理解和我上一篇一样. #include <iostream> #include <cstdio> ...
- [Javascript] Understand common misconceptions about ES6's const keyword
Values assigned with let and const are seen everywhere in JavaScript. It's become common to hear the ...