关于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版本 功能清单文档下载地址: 功 ...
随机推荐
- 【汇编】MASM6.15几个简单的汇编程序
/***************通过调用(INT 21H)表中的01h号功能号从键盘输入一个字符并回显到视频显示器上*****************/ DATAS SEGMENT ;此处输入数据段代 ...
- (转)基于Metronic的Bootstrap开发框架经验总结(6)--对话框及提示框的处理和优化
http://www.cnblogs.com/wuhuacong/p/4775282.html 在各种Web开发过程中,对话框和提示框的处理是很常见的一种界面处理技术,用得好,可以给用户很好的页面体验 ...
- X.509 certificate
A digital certificate is a collection of data used to securely distribute the public half of a publi ...
- C#判断文件是否存在 //创建txt文件
if(System.IO.File.Exists(@"")) { } if (System.IO.File.Exists(HttpRuntime.AppDomainAppPath ...
- Join 语句
select * from books as A join (select * from Orders) as B on A.BookId = B.BookId select A.BookId,Aut ...
- CF319E Ping-Pong 线段树 + vector + 思维
Code: #include<bits/stdc++.h> #define N 3000009 #define maxn 3000009 #define ll long long #def ...
- scrapy爬虫--10分钟入门
# -*- coding: utf-8 -*- # @Time : 2019/4/18 9:10 # @Author : wujf # @Email : 1028540310@qq.com # @Fi ...
- dmidecode输出详解
一.先来看几个用dmidecode查看内存信息的例子. 1.查看内存槽数.那个槽位插了内存,大小是多少 [root@jiangyi01.sqa.zmf /home/ahao.mah] #dmideco ...
- Problem 19
Problem 19 You are given the following information, but you may prefer to do some research for yours ...
- 使用VirtualBox实现端口转发,以SSH与Django为例
先来认识几个概念 (1)IP地址:又称为互联网协议地址,是计算机的物理地址,相当于计算机的编号,是32位的二进制数,通常被分割成4个8位的二进制数: (2)端口:指设备与外界通讯的接口,一台计算机的端 ...